Update more Candidate type checkers to use Candidate::is_*

This is a follow up to a previous CL that removed direct dependency on
the `cricket::` string globals.

Bug: none
Change-Id: I4d839a36739fc4694ce81b72ee036e83dae580df
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/335420
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41623}
This commit is contained in:
Tommi 2024-01-24 08:36:45 +01:00 committed by WebRTC LUCI CQ
parent 9c6874607a
commit 698b4e7087
12 changed files with 174 additions and 217 deletions

View File

@ -16,8 +16,8 @@ namespace {
const int kMinImprovement = 10; const int kMinImprovement = 10;
bool IsRelayRelay(const cricket::Connection* conn) { bool IsRelayRelay(const cricket::Connection* conn) {
return conn->local_candidate().type() == cricket::RELAY_PORT_TYPE && return conn->local_candidate().is_relay() &&
conn->remote_candidate().type() == cricket::RELAY_PORT_TYPE; conn->remote_candidate().is_relay();
} }
bool IsUdp(const cricket::Connection* conn) { bool IsUdp(const cricket::Connection* conn) {

View File

@ -75,14 +75,14 @@ inline bool TooLongWithoutResponse(
// Helper methods for converting string values of log description fields to // Helper methods for converting string values of log description fields to
// enum. // enum.
webrtc::IceCandidateType GetCandidateTypeByString(absl::string_view type) { webrtc::IceCandidateType GetRtcEventLogCandidateType(const Candidate& c) {
if (type == LOCAL_PORT_TYPE) { if (c.is_local()) {
return webrtc::IceCandidateType::kLocal; return webrtc::IceCandidateType::kLocal;
} else if (type == STUN_PORT_TYPE) { } else if (c.is_stun()) {
return webrtc::IceCandidateType::kStun; return webrtc::IceCandidateType::kStun;
} else if (type == PRFLX_PORT_TYPE) { } else if (c.is_prflx()) {
return webrtc::IceCandidateType::kPrflx; return webrtc::IceCandidateType::kPrflx;
} else if (type == RELAY_PORT_TYPE) { } else if (c.is_relay()) {
return webrtc::IceCandidateType::kRelay; return webrtc::IceCandidateType::kRelay;
} }
return webrtc::IceCandidateType::kUnknown; return webrtc::IceCandidateType::kUnknown;
@ -1367,15 +1367,13 @@ const webrtc::IceCandidatePairDescription& Connection::ToLogDescription() {
const Candidate& remote = remote_candidate(); const Candidate& remote = remote_candidate();
const rtc::Network* network = port()->Network(); const rtc::Network* network = port()->Network();
log_description_ = webrtc::IceCandidatePairDescription(); log_description_ = webrtc::IceCandidatePairDescription();
log_description_->local_candidate_type = log_description_->local_candidate_type = GetRtcEventLogCandidateType(local);
GetCandidateTypeByString(local.type());
log_description_->local_relay_protocol = log_description_->local_relay_protocol =
GetProtocolByString(local.relay_protocol()); GetProtocolByString(local.relay_protocol());
log_description_->local_network_type = ConvertNetworkType(network->type()); log_description_->local_network_type = ConvertNetworkType(network->type());
log_description_->local_address_family = log_description_->local_address_family =
GetAddressFamilyByInt(local.address().family()); GetAddressFamilyByInt(local.address().family());
log_description_->remote_candidate_type = log_description_->remote_candidate_type = GetRtcEventLogCandidateType(remote);
GetCandidateTypeByString(remote.type());
log_description_->remote_address_family = log_description_->remote_address_family =
GetAddressFamilyByInt(remote.address().family()); GetAddressFamilyByInt(remote.address().family());
log_description_->candidate_pair_protocol = log_description_->candidate_pair_protocol =

View File

@ -599,7 +599,7 @@ class P2PTransportChannelTestBase : public ::testing::Test,
return GetEndpoint(endpoint)->SetAllowTcpListen(allow_tcp_listen); return GetEndpoint(endpoint)->SetAllowTcpListen(allow_tcp_listen);
} }
// Return true if the approprite parts of the expected Result, based // Return true if the appropriate parts of the expected Result, based
// on the local and remote candidate of ep1_ch1, match. This can be // on the local and remote candidate of ep1_ch1, match. This can be
// used in an EXPECT_TRUE_WAIT. // used in an EXPECT_TRUE_WAIT.
bool CheckCandidate1(const Result& expected) { bool CheckCandidate1(const Result& expected) {
@ -613,7 +613,7 @@ class P2PTransportChannelTestBase : public ::testing::Test,
remote_type == expected.controlled_type); remote_type == expected.controlled_type);
} }
// EXPECT_EQ on the approprite parts of the expected Result, based // EXPECT_EQ on the appropriate parts of the expected Result, based
// on the local and remote candidate of ep1_ch1. This is like // on the local and remote candidate of ep1_ch1. This is like
// CheckCandidate1, except that it will provide more detail about // CheckCandidate1, except that it will provide more detail about
// what didn't match. // what didn't match.
@ -632,7 +632,7 @@ class P2PTransportChannelTestBase : public ::testing::Test,
EXPECT_EQ(expected.controlled_protocol, remote_protocol); EXPECT_EQ(expected.controlled_protocol, remote_protocol);
} }
// Return true if the approprite parts of the expected Result, based // Return true if the appropriate parts of the expected Result, based
// on the local and remote candidate of ep2_ch1, match. This can be // on the local and remote candidate of ep2_ch1, match. This can be
// used in an EXPECT_TRUE_WAIT. // used in an EXPECT_TRUE_WAIT.
bool CheckCandidate2(const Result& expected) { bool CheckCandidate2(const Result& expected) {
@ -646,7 +646,7 @@ class P2PTransportChannelTestBase : public ::testing::Test,
remote_type == expected.controlling_type); remote_type == expected.controlling_type);
} }
// EXPECT_EQ on the approprite parts of the expected Result, based // EXPECT_EQ on the appropriate parts of the expected Result, based
// on the local and remote candidate of ep2_ch1. This is like // on the local and remote candidate of ep2_ch1. This is like
// CheckCandidate2, except that it will provide more detail about // CheckCandidate2, except that it will provide more detail about
// what didn't match. // what didn't match.
@ -839,7 +839,7 @@ class P2PTransportChannelTestBase : public ::testing::Test,
// We pass the candidates directly to the other side. // We pass the candidates directly to the other side.
void OnCandidateGathered(IceTransportInternal* ch, const Candidate& c) { void OnCandidateGathered(IceTransportInternal* ch, const Candidate& c) {
if (force_relay_ && c.type() != RELAY_PORT_TYPE) if (force_relay_ && !c.is_relay())
return; return;
if (GetEndpoint(ch)->save_candidates_) { if (GetEndpoint(ch)->save_candidates_) {
@ -1571,16 +1571,16 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) {
ASSERT_TRUE_WAIT( ASSERT_TRUE_WAIT(
(selected_connection = ep1_ch1()->selected_connection()) != nullptr, (selected_connection = ep1_ch1()->selected_connection()) != nullptr,
kMediumTimeout); kMediumTimeout);
EXPECT_EQ(PRFLX_PORT_TYPE, selected_connection->remote_candidate().type()); EXPECT_TRUE(selected_connection->remote_candidate().is_prflx());
EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username()); EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username());
EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password()); EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password());
EXPECT_EQ(1u, selected_connection->remote_candidate().generation()); EXPECT_EQ(1u, selected_connection->remote_candidate().generation());
ResumeCandidates(1); ResumeCandidates(1);
// Verify ep1's selected connection is updated to use the 'local' candidate. // Verify ep1's selected connection is updated to use the 'local' candidate.
EXPECT_EQ_WAIT(LOCAL_PORT_TYPE, EXPECT_TRUE_WAIT(
ep1_ch1()->selected_connection()->remote_candidate().type(), ep1_ch1()->selected_connection()->remote_candidate().is_local(),
kMediumTimeout); kMediumTimeout);
EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection());
DestroyChannels(); DestroyChannels();
} }
@ -1608,15 +1608,15 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveRemoteCandidateIsSanitized) {
// Check the selected candidate pair. // Check the selected candidate pair.
auto pair_ep1 = ep1_ch1()->GetSelectedCandidatePair(); auto pair_ep1 = ep1_ch1()->GetSelectedCandidatePair();
ASSERT_TRUE(pair_ep1.has_value()); ASSERT_TRUE(pair_ep1.has_value());
EXPECT_EQ(PRFLX_PORT_TYPE, pair_ep1->remote_candidate().type()); EXPECT_TRUE(pair_ep1->remote_candidate().is_prflx());
EXPECT_TRUE(pair_ep1->remote_candidate().address().ipaddr().IsNil()); EXPECT_TRUE(pair_ep1->remote_candidate().address().ipaddr().IsNil());
IceTransportStats ice_transport_stats; IceTransportStats ice_transport_stats;
ep1_ch1()->GetStats(&ice_transport_stats); ep1_ch1()->GetStats(&ice_transport_stats);
// Check the candidate pair stats. // Check the candidate pair stats.
ASSERT_EQ(1u, ice_transport_stats.connection_infos.size()); ASSERT_EQ(1u, ice_transport_stats.connection_infos.size());
EXPECT_EQ(PRFLX_PORT_TYPE, EXPECT_TRUE(
ice_transport_stats.connection_infos[0].remote_candidate.type()); ice_transport_stats.connection_infos[0].remote_candidate.is_prflx());
EXPECT_TRUE(ice_transport_stats.connection_infos[0] EXPECT_TRUE(ice_transport_stats.connection_infos[0]
.remote_candidate.address() .remote_candidate.address()
.ipaddr() .ipaddr()
@ -1626,8 +1626,7 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveRemoteCandidateIsSanitized) {
ResumeCandidates(1); ResumeCandidates(1);
ASSERT_TRUE_WAIT( ASSERT_TRUE_WAIT(
ep1_ch1()->selected_connection() != nullptr && ep1_ch1()->selected_connection() != nullptr &&
ep1_ch1()->selected_connection()->remote_candidate().type() == ep1_ch1()->selected_connection()->remote_candidate().is_local(),
LOCAL_PORT_TYPE,
kMediumTimeout); kMediumTimeout);
// We should be able to reveal the address after it is learnt via // We should be able to reveal the address after it is learnt via
@ -1636,14 +1635,14 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveRemoteCandidateIsSanitized) {
// Check the selected candidate pair. // Check the selected candidate pair.
auto updated_pair_ep1 = ep1_ch1()->GetSelectedCandidatePair(); auto updated_pair_ep1 = ep1_ch1()->GetSelectedCandidatePair();
ASSERT_TRUE(updated_pair_ep1.has_value()); ASSERT_TRUE(updated_pair_ep1.has_value());
EXPECT_EQ(LOCAL_PORT_TYPE, updated_pair_ep1->remote_candidate().type()); EXPECT_TRUE(updated_pair_ep1->remote_candidate().is_local());
EXPECT_TRUE(HasRemoteAddress(&updated_pair_ep1.value(), kPublicAddrs[1])); EXPECT_TRUE(HasRemoteAddress(&updated_pair_ep1.value(), kPublicAddrs[1]));
ep1_ch1()->GetStats(&ice_transport_stats); ep1_ch1()->GetStats(&ice_transport_stats);
// Check the candidate pair stats. // Check the candidate pair stats.
ASSERT_EQ(1u, ice_transport_stats.connection_infos.size()); ASSERT_EQ(1u, ice_transport_stats.connection_infos.size());
EXPECT_EQ(LOCAL_PORT_TYPE, EXPECT_TRUE(
ice_transport_stats.connection_infos[0].remote_candidate.type()); ice_transport_stats.connection_infos[0].remote_candidate.is_local());
EXPECT_TRUE(ice_transport_stats.connection_infos[0] EXPECT_TRUE(ice_transport_stats.connection_infos[0]
.remote_candidate.address() .remote_candidate.address()
.EqualIPs(kPublicAddrs[1])); .EqualIPs(kPublicAddrs[1]));
@ -1679,16 +1678,16 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) {
ASSERT_TRUE_WAIT( ASSERT_TRUE_WAIT(
(selected_connection = ep1_ch1()->selected_connection()) != nullptr, (selected_connection = ep1_ch1()->selected_connection()) != nullptr,
kMediumTimeout); kMediumTimeout);
EXPECT_EQ(PRFLX_PORT_TYPE, selected_connection->remote_candidate().type()); EXPECT_TRUE(selected_connection->remote_candidate().is_prflx());
EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username()); EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username());
EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password()); EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password());
EXPECT_EQ(1u, selected_connection->remote_candidate().generation()); EXPECT_EQ(1u, selected_connection->remote_candidate().generation());
ResumeCandidates(1); ResumeCandidates(1);
EXPECT_EQ_WAIT(PRFLX_PORT_TYPE, EXPECT_TRUE_WAIT(
ep1_ch1()->selected_connection()->remote_candidate().type(), ep1_ch1()->selected_connection()->remote_candidate().is_prflx(),
kMediumTimeout); kMediumTimeout);
EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection());
DestroyChannels(); DestroyChannels();
} }
@ -1728,9 +1727,9 @@ TEST_F(P2PTransportChannelTest,
// The caller should have the selected connection connected to the peer // The caller should have the selected connection connected to the peer
// reflexive candidate. // reflexive candidate.
EXPECT_EQ_WAIT(PRFLX_PORT_TYPE, EXPECT_TRUE_WAIT(
ep1_ch1()->selected_connection()->remote_candidate().type(), ep1_ch1()->selected_connection()->remote_candidate().is_prflx(),
kDefaultTimeout); kDefaultTimeout);
const Connection* prflx_selected_connection = const Connection* prflx_selected_connection =
ep1_ch1()->selected_connection(); ep1_ch1()->selected_connection();
@ -1744,9 +1743,9 @@ TEST_F(P2PTransportChannelTest,
// their information to update the peer reflexive candidate. // their information to update the peer reflexive candidate.
ResumeCandidates(1); ResumeCandidates(1);
EXPECT_EQ_WAIT(RELAY_PORT_TYPE, EXPECT_TRUE_WAIT(
ep1_ch1()->selected_connection()->remote_candidate().type(), ep1_ch1()->selected_connection()->remote_candidate().is_relay(),
kDefaultTimeout); kDefaultTimeout);
EXPECT_EQ(prflx_selected_connection, ep1_ch1()->selected_connection()); EXPECT_EQ(prflx_selected_connection, ep1_ch1()->selected_connection());
DestroyChannels(); DestroyChannels();
} }
@ -2021,10 +2020,10 @@ TEST_F(P2PTransportChannelTest, TestForceTurn) {
EXPECT_TRUE(ep1_ch1()->selected_connection() && EXPECT_TRUE(ep1_ch1()->selected_connection() &&
ep2_ch1()->selected_connection()); ep2_ch1()->selected_connection());
EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); EXPECT_TRUE(RemoteCandidate(ep1_ch1())->is_relay());
EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); EXPECT_TRUE(LocalCandidate(ep1_ch1())->is_relay());
EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep2_ch1())->type()); EXPECT_TRUE(RemoteCandidate(ep2_ch1())->is_relay());
EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep2_ch1())->type()); EXPECT_TRUE(LocalCandidate(ep2_ch1())->is_relay());
TestSendRecv(&clock); TestSendRecv(&clock);
DestroyChannels(); DestroyChannels();
@ -2172,8 +2171,8 @@ TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) {
// Expect that the TURN-TURN candidate pair will be prioritized since it's // Expect that the TURN-TURN candidate pair will be prioritized since it's
// "probably writable". // "probably writable".
EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() != nullptr, kShortTimeout); EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() != nullptr, kShortTimeout);
EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); EXPECT_TRUE(LocalCandidate(ep1_ch1())->is_relay());
EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); EXPECT_TRUE(RemoteCandidate(ep1_ch1())->is_relay());
// Also expect that the channel instantly indicates that it's writable since // Also expect that the channel instantly indicates that it's writable since
// it has a TURN-TURN pair. // it has a TURN-TURN pair.
EXPECT_TRUE(ep1_ch1()->writable()); EXPECT_TRUE(ep1_ch1()->writable());
@ -2220,8 +2219,8 @@ TEST_F(P2PTransportChannelTest, TurnToPrflxPresumedWritable) {
EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable(), EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable(),
kShortTimeout, fake_clock); kShortTimeout, fake_clock);
ASSERT_NE(nullptr, ep1_ch1()->selected_connection()); ASSERT_NE(nullptr, ep1_ch1()->selected_connection());
EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); EXPECT_TRUE(LocalCandidate(ep1_ch1())->is_relay());
EXPECT_EQ(PRFLX_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); EXPECT_TRUE(RemoteCandidate(ep1_ch1())->is_prflx());
// Make sure that at this point the connection is only presumed writable, // Make sure that at this point the connection is only presumed writable,
// not fully writable. // not fully writable.
EXPECT_FALSE(ep1_ch1()->selected_connection()->writable()); EXPECT_FALSE(ep1_ch1()->selected_connection()->writable());
@ -2265,8 +2264,8 @@ TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) {
// port available to make a TURN<->TURN pair that's presumed writable. // port available to make a TURN<->TURN pair that's presumed writable.
ep1_ch1()->AddRemoteCandidate( ep1_ch1()->AddRemoteCandidate(
CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 0)); CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 0));
EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); EXPECT_TRUE(LocalCandidate(ep1_ch1())->is_relay());
EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); EXPECT_TRUE(RemoteCandidate(ep1_ch1())->is_relay());
EXPECT_TRUE(ep1_ch1()->writable()); EXPECT_TRUE(ep1_ch1()->writable());
EXPECT_TRUE(GetEndpoint(0)->ready_to_send_); EXPECT_TRUE(GetEndpoint(0)->ready_to_send_);
EXPECT_NE(old_selected_connection, ep1_ch1()->selected_connection()); EXPECT_NE(old_selected_connection, ep1_ch1()->selected_connection());
@ -2293,8 +2292,8 @@ TEST_F(P2PTransportChannelTest, SignalReadyToSendWithPresumedWritable) {
CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 0)); CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 0));
// Sanity checking the type of the connection. // Sanity checking the type of the connection.
EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() != nullptr, kShortTimeout); EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() != nullptr, kShortTimeout);
EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); EXPECT_TRUE(LocalCandidate(ep1_ch1())->is_relay());
EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); EXPECT_TRUE(RemoteCandidate(ep1_ch1())->is_relay());
// Tell the socket server to block packets (returning EWOULDBLOCK). // Tell the socket server to block packets (returning EWOULDBLOCK).
virtual_socket_server()->SetSendingBlocked(true); virtual_socket_server()->SetSendingBlocked(true);
@ -2349,8 +2348,8 @@ TEST_F(P2PTransportChannelTest,
ASSERT_NE(nullptr, ep1_ch1()->selected_connection()); ASSERT_NE(nullptr, ep1_ch1()->selected_connection());
EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); EXPECT_TRUE(LocalCandidate(ep1_ch1())->is_relay());
EXPECT_EQ(PRFLX_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); EXPECT_TRUE(RemoteCandidate(ep1_ch1())->is_prflx());
DestroyChannels(); DestroyChannels();
} }
@ -5041,22 +5040,22 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
// Relay/Relay should be the first pingable connection. // Relay/Relay should be the first pingable connection.
Connection* conn = FindNextPingableConnectionAndPingIt(&ch); Connection* conn = FindNextPingableConnectionAndPingIt(&ch);
ASSERT_TRUE(conn != nullptr); ASSERT_TRUE(conn != nullptr);
EXPECT_EQ(conn->local_candidate().type(), RELAY_PORT_TYPE); EXPECT_TRUE(conn->local_candidate().is_relay());
EXPECT_EQ(conn->remote_candidate().type(), RELAY_PORT_TYPE); EXPECT_TRUE(conn->remote_candidate().is_relay());
// Unless that we have a trigger check waiting to be pinged. // Unless that we have a trigger check waiting to be pinged.
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr); ASSERT_TRUE(conn2 != nullptr);
EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE); EXPECT_TRUE(conn2->local_candidate().is_local());
EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE); EXPECT_TRUE(conn2->remote_candidate().is_local());
conn2->ReceivedPing(); conn2->ReceivedPing();
EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
// Make conn3 the selected connection. // Make conn3 the selected connection.
Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn3 != nullptr); ASSERT_TRUE(conn3 != nullptr);
EXPECT_EQ(conn3->local_candidate().type(), LOCAL_PORT_TYPE); EXPECT_TRUE(conn3->local_candidate().is_local());
EXPECT_EQ(conn3->remote_candidate().type(), RELAY_PORT_TYPE); EXPECT_TRUE(conn3->remote_candidate().is_relay());
conn3->ReceivedPingResponse(LOW_RTT, "id"); conn3->ReceivedPingResponse(LOW_RTT, "id");
ASSERT_TRUE(conn3->writable()); ASSERT_TRUE(conn3->writable());
conn3->ReceivedPing(); conn3->ReceivedPing();
@ -5266,16 +5265,16 @@ TEST_F(P2PTransportChannelTest,
ASSERT_TRUE_WAIT( ASSERT_TRUE_WAIT(
(selected_connection = ep2_ch1()->selected_connection()) != nullptr, (selected_connection = ep2_ch1()->selected_connection()) != nullptr,
kMediumTimeout); kMediumTimeout);
EXPECT_EQ(PRFLX_PORT_TYPE, selected_connection->remote_candidate().type()); EXPECT_TRUE(selected_connection->remote_candidate().is_prflx());
EXPECT_EQ(kIceUfrag[0], selected_connection->remote_candidate().username()); EXPECT_EQ(kIceUfrag[0], selected_connection->remote_candidate().username());
EXPECT_EQ(kIcePwd[0], selected_connection->remote_candidate().password()); EXPECT_EQ(kIcePwd[0], selected_connection->remote_candidate().password());
// Set expectation before ep1 signals a hostname candidate. // Set expectation before ep1 signals a hostname candidate.
resolver_fixture.SetAddressToReturn(local_address); resolver_fixture.SetAddressToReturn(local_address);
ResumeCandidates(0); ResumeCandidates(0);
// Verify ep2's selected connection is updated to use the 'local' candidate. // Verify ep2's selected connection is updated to use the 'local' candidate.
EXPECT_EQ_WAIT(LOCAL_PORT_TYPE, EXPECT_TRUE_WAIT(
ep2_ch1()->selected_connection()->remote_candidate().type(), ep2_ch1()->selected_connection()->remote_candidate().is_local(),
kMediumTimeout); kMediumTimeout);
EXPECT_EQ(selected_connection, ep2_ch1()->selected_connection()); EXPECT_EQ(selected_connection, ep2_ch1()->selected_connection());
DestroyChannels(); DestroyChannels();
@ -5328,16 +5327,15 @@ TEST_F(P2PTransportChannelTest,
// There is a caveat in our implementation associated with this expectation. // There is a caveat in our implementation associated with this expectation.
// See the big comment in P2PTransportChannel::OnUnknownAddress. // See the big comment in P2PTransportChannel::OnUnknownAddress.
ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, kMediumTimeout); ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, kMediumTimeout);
EXPECT_EQ(PRFLX_PORT_TYPE, EXPECT_TRUE(ep2_ch1()->selected_connection()->remote_candidate().is_prflx());
ep2_ch1()->selected_connection()->remote_candidate().type());
// ep2 should also be able resolve the hostname candidate. The resolved remote // ep2 should also be able resolve the hostname candidate. The resolved remote
// host candidate should be merged with the prflx remote candidate. // host candidate should be merged with the prflx remote candidate.
resolver_fixture.FireDelayedResolution(); resolver_fixture.FireDelayedResolution();
EXPECT_EQ_WAIT(LOCAL_PORT_TYPE, EXPECT_TRUE_WAIT(
ep2_ch1()->selected_connection()->remote_candidate().type(), ep2_ch1()->selected_connection()->remote_candidate().is_local(),
kMediumTimeout); kMediumTimeout);
EXPECT_EQ(1u, ep2_ch1()->remote_candidates().size()); EXPECT_EQ(1u, ep2_ch1()->remote_candidates().size());
DestroyChannels(); DestroyChannels();
@ -5380,10 +5378,8 @@ TEST_F(P2PTransportChannelTest, CanConnectWithHostCandidateWithMdnsName) {
// with a peer reflexive candidate from ep2. // with a peer reflexive candidate from ep2.
ASSERT_TRUE_WAIT((ep1_ch1()->selected_connection()) != nullptr, ASSERT_TRUE_WAIT((ep1_ch1()->selected_connection()) != nullptr,
kMediumTimeout); kMediumTimeout);
EXPECT_EQ(LOCAL_PORT_TYPE, EXPECT_TRUE(ep1_ch1()->selected_connection()->local_candidate().is_local());
ep1_ch1()->selected_connection()->local_candidate().type()); EXPECT_TRUE(ep1_ch1()->selected_connection()->remote_candidate().is_prflx());
EXPECT_EQ(PRFLX_PORT_TYPE,
ep1_ch1()->selected_connection()->remote_candidate().type());
DestroyChannels(); DestroyChannels();
} }
@ -5713,10 +5709,8 @@ TEST_F(P2PTransportChannelTest,
// We should be able to form a srflx-host connection to ep2. // We should be able to form a srflx-host connection to ep2.
ASSERT_TRUE_WAIT((ep1_ch1()->selected_connection()) != nullptr, ASSERT_TRUE_WAIT((ep1_ch1()->selected_connection()) != nullptr,
kMediumTimeout); kMediumTimeout);
EXPECT_EQ(STUN_PORT_TYPE, EXPECT_TRUE(ep1_ch1()->selected_connection()->local_candidate().is_stun());
ep1_ch1()->selected_connection()->local_candidate().type()); EXPECT_TRUE(ep1_ch1()->selected_connection()->remote_candidate().is_local());
EXPECT_EQ(LOCAL_PORT_TYPE,
ep1_ch1()->selected_connection()->remote_candidate().type());
DestroyChannels(); DestroyChannels();
} }
@ -5747,31 +5741,25 @@ TEST_F(P2PTransportChannelTest,
kDefaultTimeout, clock); kDefaultTimeout, clock);
ASSERT_TRUE_SIMULATED_WAIT(ep2_ch1()->selected_connection() != nullptr, ASSERT_TRUE_SIMULATED_WAIT(ep2_ch1()->selected_connection() != nullptr,
kDefaultTimeout, clock); kDefaultTimeout, clock);
EXPECT_EQ(RELAY_PORT_TYPE, EXPECT_TRUE(ep1_ch1()->selected_connection()->local_candidate().is_relay());
ep1_ch1()->selected_connection()->local_candidate().type()); EXPECT_TRUE(ep2_ch1()->selected_connection()->local_candidate().is_relay());
EXPECT_EQ(RELAY_PORT_TYPE,
ep2_ch1()->selected_connection()->local_candidate().type());
// Loosen the candidate filter at ep1. // Loosen the candidate filter at ep1.
ep1->allocator_->SetCandidateFilter(CF_ALL); ep1->allocator_->SetCandidateFilter(CF_ALL);
EXPECT_TRUE_SIMULATED_WAIT( EXPECT_TRUE_SIMULATED_WAIT(
ep1_ch1()->selected_connection() != nullptr && ep1_ch1()->selected_connection() != nullptr &&
ep1_ch1()->selected_connection()->local_candidate().type() == ep1_ch1()->selected_connection()->local_candidate().is_local(),
LOCAL_PORT_TYPE,
kDefaultTimeout, clock); kDefaultTimeout, clock);
EXPECT_EQ(RELAY_PORT_TYPE, EXPECT_TRUE(ep1_ch1()->selected_connection()->remote_candidate().is_relay());
ep1_ch1()->selected_connection()->remote_candidate().type());
// Loosen the candidate filter at ep2. // Loosen the candidate filter at ep2.
ep2->allocator_->SetCandidateFilter(CF_ALL); ep2->allocator_->SetCandidateFilter(CF_ALL);
EXPECT_TRUE_SIMULATED_WAIT( EXPECT_TRUE_SIMULATED_WAIT(
ep2_ch1()->selected_connection() != nullptr && ep2_ch1()->selected_connection() != nullptr &&
ep2_ch1()->selected_connection()->local_candidate().type() == ep2_ch1()->selected_connection()->local_candidate().is_local(),
LOCAL_PORT_TYPE,
kDefaultTimeout, clock); kDefaultTimeout, clock);
// We have migrated to a host-host candidate pair. // We have migrated to a host-host candidate pair.
EXPECT_EQ(LOCAL_PORT_TYPE, EXPECT_TRUE(ep2_ch1()->selected_connection()->remote_candidate().is_local());
ep2_ch1()->selected_connection()->remote_candidate().type());
// Block the traffic over non-relay-to-relay routes and expect a route change. // Block the traffic over non-relay-to-relay routes and expect a route change.
fw()->AddRule(false, rtc::FP_ANY, kPublicAddrs[0], kPublicAddrs[1]); fw()->AddRule(false, rtc::FP_ANY, kPublicAddrs[0], kPublicAddrs[1]);
@ -5780,12 +5768,10 @@ TEST_F(P2PTransportChannelTest,
fw()->AddRule(false, rtc::FP_ANY, kPublicAddrs[1], kTurnUdpExtAddr); fw()->AddRule(false, rtc::FP_ANY, kPublicAddrs[1], kTurnUdpExtAddr);
// We should be able to reuse the previously gathered relay candidates. // We should be able to reuse the previously gathered relay candidates.
EXPECT_EQ_SIMULATED_WAIT( EXPECT_TRUE_SIMULATED_WAIT(
RELAY_PORT_TYPE, ep1_ch1()->selected_connection()->local_candidate().is_relay(),
ep1_ch1()->selected_connection()->local_candidate().type(),
kDefaultTimeout, clock); kDefaultTimeout, clock);
EXPECT_EQ(RELAY_PORT_TYPE, EXPECT_TRUE(ep1_ch1()->selected_connection()->remote_candidate().is_relay());
ep1_ch1()->selected_connection()->remote_candidate().type());
DestroyChannels(); DestroyChannels();
} }
@ -5824,22 +5810,18 @@ TEST_F(P2PTransportChannelTest,
ep1->allocator_->SetCandidateFilter(kCandidateFilterNoHost); ep1->allocator_->SetCandidateFilter(kCandidateFilterNoHost);
EXPECT_TRUE_SIMULATED_WAIT( EXPECT_TRUE_SIMULATED_WAIT(
ep1_ch1()->selected_connection() != nullptr && ep1_ch1()->selected_connection() != nullptr &&
ep1_ch1()->selected_connection()->local_candidate().type() == ep1_ch1()->selected_connection()->local_candidate().is_stun(),
STUN_PORT_TYPE,
kDefaultTimeout, clock); kDefaultTimeout, clock);
EXPECT_EQ(RELAY_PORT_TYPE, EXPECT_TRUE(ep1_ch1()->selected_connection()->remote_candidate().is_relay());
ep1_ch1()->selected_connection()->remote_candidate().type());
// Loosen the candidate filter at ep2. // Loosen the candidate filter at ep2.
ep2->allocator_->SetCandidateFilter(kCandidateFilterNoHost); ep2->allocator_->SetCandidateFilter(kCandidateFilterNoHost);
EXPECT_TRUE_SIMULATED_WAIT( EXPECT_TRUE_SIMULATED_WAIT(
ep2_ch1()->selected_connection() != nullptr && ep2_ch1()->selected_connection() != nullptr &&
ep2_ch1()->selected_connection()->local_candidate().type() == ep2_ch1()->selected_connection()->local_candidate().is_stun(),
STUN_PORT_TYPE,
kDefaultTimeout, clock); kDefaultTimeout, clock);
// We have migrated to a srflx-srflx candidate pair. // We have migrated to a srflx-srflx candidate pair.
EXPECT_EQ(STUN_PORT_TYPE, EXPECT_TRUE(ep2_ch1()->selected_connection()->remote_candidate().is_stun());
ep2_ch1()->selected_connection()->remote_candidate().type());
// Block the traffic over non-relay-to-relay routes and expect a route change. // Block the traffic over non-relay-to-relay routes and expect a route change.
fw()->AddRule(false, rtc::FP_ANY, kPrivateAddrs[0], kPublicAddrs[1]); fw()->AddRule(false, rtc::FP_ANY, kPrivateAddrs[0], kPublicAddrs[1]);
@ -5847,12 +5829,10 @@ TEST_F(P2PTransportChannelTest,
fw()->AddRule(false, rtc::FP_ANY, kPrivateAddrs[0], kTurnUdpExtAddr); fw()->AddRule(false, rtc::FP_ANY, kPrivateAddrs[0], kTurnUdpExtAddr);
fw()->AddRule(false, rtc::FP_ANY, kPrivateAddrs[1], kTurnUdpExtAddr); fw()->AddRule(false, rtc::FP_ANY, kPrivateAddrs[1], kTurnUdpExtAddr);
// We should be able to reuse the previously gathered relay candidates. // We should be able to reuse the previously gathered relay candidates.
EXPECT_EQ_SIMULATED_WAIT( EXPECT_TRUE_SIMULATED_WAIT(
RELAY_PORT_TYPE, ep1_ch1()->selected_connection()->local_candidate().is_relay(),
ep1_ch1()->selected_connection()->local_candidate().type(),
kDefaultTimeout, clock); kDefaultTimeout, clock);
EXPECT_EQ(RELAY_PORT_TYPE, EXPECT_TRUE(ep1_ch1()->selected_connection()->remote_candidate().is_relay());
ep1_ch1()->selected_connection()->remote_candidate().type());
DestroyChannels(); DestroyChannels();
} }
@ -5885,13 +5865,11 @@ TEST_F(P2PTransportChannelTest,
ep1->allocator_->SetCandidateFilter(CF_ALL); ep1->allocator_->SetCandidateFilter(CF_ALL);
// Wait for a period for any potential surfacing of new candidates. // Wait for a period for any potential surfacing of new candidates.
SIMULATED_WAIT(false, kDefaultTimeout, clock); SIMULATED_WAIT(false, kDefaultTimeout, clock);
EXPECT_EQ(RELAY_PORT_TYPE, EXPECT_TRUE(ep1_ch1()->selected_connection()->local_candidate().is_relay());
ep1_ch1()->selected_connection()->local_candidate().type());
// Loosen the candidate filter at ep2. // Loosen the candidate filter at ep2.
ep2->allocator_->SetCandidateFilter(CF_ALL); ep2->allocator_->SetCandidateFilter(CF_ALL);
EXPECT_EQ(RELAY_PORT_TYPE, EXPECT_TRUE(ep2_ch1()->selected_connection()->local_candidate().is_relay());
ep2_ch1()->selected_connection()->local_candidate().type());
DestroyChannels(); DestroyChannels();
} }
@ -5928,21 +5906,18 @@ TEST_F(P2PTransportChannelTest,
ResumeCandidates(1); ResumeCandidates(1);
ASSERT_TRUE_SIMULATED_WAIT( ASSERT_TRUE_SIMULATED_WAIT(
ep1_ch1()->selected_connection() != nullptr && ep1_ch1()->selected_connection() != nullptr &&
LOCAL_PORT_TYPE == ep1_ch1()->selected_connection()->local_candidate().is_local() &&
ep1_ch1()->selected_connection()->local_candidate().type() &&
ep2_ch1()->selected_connection() != nullptr && ep2_ch1()->selected_connection() != nullptr &&
LOCAL_PORT_TYPE == ep1_ch1()->selected_connection()->remote_candidate().is_local(),
ep1_ch1()->selected_connection()->remote_candidate().type(),
kDefaultTimeout, clock); kDefaultTimeout, clock);
ASSERT_TRUE_SIMULATED_WAIT(ep2_ch1()->selected_connection() != nullptr, ASSERT_TRUE_SIMULATED_WAIT(ep2_ch1()->selected_connection() != nullptr,
kDefaultTimeout, clock); kDefaultTimeout, clock);
// Test that we have a host-host candidate pair selected and the number of // Test that we have a host-host candidate pair selected and the number of
// candidates signaled to the remote peer stays the same. // candidates signaled to the remote peer stays the same.
auto test_invariants = [this]() { auto test_invariants = [this]() {
EXPECT_EQ(LOCAL_PORT_TYPE, EXPECT_TRUE(ep1_ch1()->selected_connection()->local_candidate().is_local());
ep1_ch1()->selected_connection()->local_candidate().type()); EXPECT_TRUE(
EXPECT_EQ(LOCAL_PORT_TYPE, ep1_ch1()->selected_connection()->remote_candidate().is_local());
ep1_ch1()->selected_connection()->remote_candidate().type());
EXPECT_THAT(ep2_ch1()->remote_candidates(), SizeIs(3)); EXPECT_THAT(ep2_ch1()->remote_candidates(), SizeIs(3));
}; };
@ -6005,11 +5980,9 @@ TEST_F(P2PTransportChannelTest, SurfaceRequiresCoordination) {
ResumeCandidates(1); ResumeCandidates(1);
ASSERT_TRUE_SIMULATED_WAIT( ASSERT_TRUE_SIMULATED_WAIT(
ep1_ch1()->selected_connection() != nullptr && ep1_ch1()->selected_connection() != nullptr &&
RELAY_PORT_TYPE == ep1_ch1()->selected_connection()->local_candidate().is_relay() &&
ep1_ch1()->selected_connection()->local_candidate().type() &&
ep2_ch1()->selected_connection() != nullptr && ep2_ch1()->selected_connection() != nullptr &&
RELAY_PORT_TYPE == ep1_ch1()->selected_connection()->remote_candidate().is_relay(),
ep1_ch1()->selected_connection()->remote_candidate().type(),
kDefaultTimeout, clock); kDefaultTimeout, clock);
ASSERT_TRUE_SIMULATED_WAIT(ep2_ch1()->selected_connection() != nullptr, ASSERT_TRUE_SIMULATED_WAIT(ep2_ch1()->selected_connection() != nullptr,
kDefaultTimeout, clock); kDefaultTimeout, clock);
@ -6025,11 +5998,9 @@ TEST_F(P2PTransportChannelTest, SurfaceRequiresCoordination) {
// No p2p connection will be made, it will remain on relay. // No p2p connection will be made, it will remain on relay.
EXPECT_TRUE(ep1_ch1()->selected_connection() != nullptr && EXPECT_TRUE(ep1_ch1()->selected_connection() != nullptr &&
RELAY_PORT_TYPE == ep1_ch1()->selected_connection()->local_candidate().is_relay() &&
ep1_ch1()->selected_connection()->local_candidate().type() &&
ep2_ch1()->selected_connection() != nullptr && ep2_ch1()->selected_connection() != nullptr &&
RELAY_PORT_TYPE == ep1_ch1()->selected_connection()->remote_candidate().is_relay());
ep1_ch1()->selected_connection()->remote_candidate().type());
DestroyChannels(); DestroyChannels();
} }

View File

@ -259,14 +259,18 @@ void Port::AddAddress(const rtc::SocketAddress& address,
absl::string_view url, absl::string_view url,
bool is_final) { bool is_final) {
RTC_DCHECK_RUN_ON(thread_); RTC_DCHECK_RUN_ON(thread_);
if (protocol == TCP_PROTOCOL_NAME && type == LOCAL_PORT_TYPE) {
RTC_DCHECK(!tcptype.empty());
}
std::string foundation = std::string foundation =
ComputeFoundation(type, protocol, relay_protocol, base_address); ComputeFoundation(type, protocol, relay_protocol, base_address);
Candidate c(component_, protocol, address, 0U, username_fragment(), password_, Candidate c(component_, protocol, address, 0U, username_fragment(), password_,
type, generation_, foundation, network_->id(), network_cost_); type, generation_, foundation, network_->id(), network_cost_);
#if RTC_DCHECK_IS_ON
if (protocol == TCP_PROTOCOL_NAME && c.is_local()) {
RTC_DCHECK(!tcptype.empty());
}
#endif
c.set_relay_protocol(relay_protocol); c.set_relay_protocol(relay_protocol);
c.set_priority( c.set_priority(
c.GetPriority(type_preference, network_->preference(), relay_preference, c.GetPriority(type_preference, network_->preference(), relay_preference,
@ -279,26 +283,24 @@ void Port::AddAddress(const rtc::SocketAddress& address,
c.set_url(url); c.set_url(url);
c.set_related_address(related_address); c.set_related_address(related_address);
bool pending = MaybeObfuscateAddress(&c, type, is_final); bool pending = MaybeObfuscateAddress(c, is_final);
if (!pending) { if (!pending) {
FinishAddingAddress(c, is_final); FinishAddingAddress(c, is_final);
} }
} }
bool Port::MaybeObfuscateAddress(Candidate* c, bool Port::MaybeObfuscateAddress(const Candidate& c, bool is_final) {
absl::string_view type,
bool is_final) {
// TODO(bugs.webrtc.org/9723): Use a config to control the feature of IP // TODO(bugs.webrtc.org/9723): Use a config to control the feature of IP
// handling with mDNS. // handling with mDNS.
if (network_->GetMdnsResponder() == nullptr) { if (network_->GetMdnsResponder() == nullptr) {
return false; return false;
} }
if (type != LOCAL_PORT_TYPE) { if (!c.is_local()) {
return false; return false;
} }
auto copy = *c; auto copy = c;
auto weak_ptr = weak_factory_.GetWeakPtr(); auto weak_ptr = weak_factory_.GetWeakPtr();
auto callback = [weak_ptr, copy, is_final](const rtc::IPAddress& addr, auto callback = [weak_ptr, copy, is_final](const rtc::IPAddress& addr,
absl::string_view name) mutable { absl::string_view name) mutable {

View File

@ -199,8 +199,8 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> {
// Note that the port type does NOT uniquely identify different subclasses of // Note that the port type does NOT uniquely identify different subclasses of
// Port. Use the 2-tuple of the port type AND the protocol (GetProtocol()) to // Port. Use the 2-tuple of the port type AND the protocol (GetProtocol()) to
// uniquely identify subclasses. Whenever a new subclass of Port introduces a // uniquely identify subclasses. Whenever a new subclass of Port introduces a
// conflit in the value of the 2-tuple, make sure that the implementation that // conflict in the value of the 2-tuple, make sure that the implementation
// relies on this 2-tuple for RTTI is properly changed. // that relies on this 2-tuple for RTTI is properly changed.
const absl::string_view Type() const override; const absl::string_view Type() const override;
const rtc::Network* Network() const override; const rtc::Network* Network() const override;
@ -525,9 +525,8 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> {
webrtc::FieldTrialBasedConfig> webrtc::FieldTrialBasedConfig>
field_trials_; field_trials_;
bool MaybeObfuscateAddress(Candidate* c, bool MaybeObfuscateAddress(const Candidate& c, bool is_final)
absl::string_view type, RTC_RUN_ON(thread_);
bool is_final) RTC_RUN_ON(thread_);
webrtc::CallbackList<PortInterface*> port_destroyed_callback_list_; webrtc::CallbackList<PortInterface*> port_destroyed_callback_list_;
}; };

View File

@ -426,7 +426,7 @@ TEST_F(StunPortTest, TestStunCandidateDiscardedWithMdnsObfuscationNotEnabled) {
EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
ASSERT_EQ(1U, port()->Candidates().size()); ASSERT_EQ(1U, port()->Candidates().size());
EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address())); EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
EXPECT_EQ(port()->Candidates()[0].type(), cricket::LOCAL_PORT_TYPE); EXPECT_TRUE(port()->Candidates()[0].is_local());
} }
// Test that a stun candidate (srflx candidate) is generated whose address is // Test that a stun candidate (srflx candidate) is generated whose address is

View File

@ -134,8 +134,7 @@ Connection* TCPPort::CreateConnection(const Candidate& address,
return NULL; return NULL;
} }
if ((address.tcptype() == TCPTYPE_ACTIVE_STR && if ((address.tcptype() == TCPTYPE_ACTIVE_STR && !address.is_prflx()) ||
address.type() != PRFLX_PORT_TYPE) ||
(address.tcptype().empty() && address.address().port() == 0)) { (address.tcptype().empty() && address.address().port() == 0)) {
// It's active only candidate, we should not try to create connections // It's active only candidate, we should not try to create connections
// for these candidates. // for these candidates.

View File

@ -328,17 +328,6 @@ class BasicPortAllocatorTestBase : public ::testing::Test,
}); });
} }
static int CountCandidates(const std::vector<Candidate>& candidates,
absl::string_view type,
absl::string_view proto,
const SocketAddress& addr) {
return absl::c_count_if(
candidates, [type, proto, addr](const Candidate& c) {
return c.type() == type && c.protocol() == proto &&
AddressMatch(c.address(), addr);
});
}
// Find a candidate and return it. // Find a candidate and return it.
static bool FindCandidate(const std::vector<Candidate>& candidates, static bool FindCandidate(const std::vector<Candidate>& candidates,
absl::string_view type, absl::string_view type,
@ -1237,7 +1226,7 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) {
int num_nonrelay_candidates = 0; int num_nonrelay_candidates = 0;
for (const Candidate& candidate : candidates_) { for (const Candidate& candidate : candidates_) {
// Check the port number for the UDP/STUN/TCP port objects. // Check the port number for the UDP/STUN/TCP port objects.
if (candidate.type() != RELAY_PORT_TYPE) { if (!candidate.is_relay()) {
EXPECT_TRUE(CheckPort(candidate.address(), kMinPort, kMaxPort)); EXPECT_TRUE(CheckPort(candidate.address(), kMinPort, kMaxPort));
++num_nonrelay_candidates; ++num_nonrelay_candidates;
} }
@ -1272,9 +1261,11 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoAdapters) {
rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0))); rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)));
// Again, two TURN candidates, using UDP/TCP for the first hop to the TURN // Again, two TURN candidates, using UDP/TCP for the first hop to the TURN
// server. // server.
EXPECT_EQ(2, rtc::SocketAddress addr(kTurnUdpExtAddr.ipaddr(), 0);
CountCandidates(candidates_, "relay", "udp", EXPECT_EQ(2, absl::c_count_if(candidates_, [&](const Candidate& c) {
rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0))); return c.is_relay() && c.protocol() == "udp" &&
AddressMatch(c.address(), addr);
}));
} }
// Test that when enumeration is disabled, we should not have any ports when // Test that when enumeration is disabled, we should not have any ports when
@ -1548,7 +1539,7 @@ TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) {
EXPECT_EQ(1U, candidates_.size()); EXPECT_EQ(1U, candidates_.size());
EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state. EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state.
EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidates_[0].type()); EXPECT_TRUE(candidates_[0].is_relay());
EXPECT_EQ( EXPECT_EQ(
candidates_[0].related_address(), candidates_[0].related_address(),
rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()));
@ -1565,7 +1556,7 @@ TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithHostOnly) {
EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only.
EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only.
for (const Candidate& candidate : candidates_) { for (const Candidate& candidate : candidates_) {
EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type()); EXPECT_TRUE(candidate.is_local());
} }
} }
@ -1584,7 +1575,7 @@ TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) {
// port with STUN candidate will be sent outside. // port with STUN candidate will be sent outside.
EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate.
EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state.
EXPECT_EQ(std::string(STUN_PORT_TYPE), candidates_[0].type()); EXPECT_TRUE(candidates_[0].is_stun());
EXPECT_EQ( EXPECT_EQ(
candidates_[0].related_address(), candidates_[0].related_address(),
rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()));
@ -1603,7 +1594,7 @@ TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) {
EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate.
EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state.
for (const Candidate& candidate : candidates_) { for (const Candidate& candidate : candidates_) {
EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type()); EXPECT_TRUE(candidate.is_local());
} }
} }
@ -2174,7 +2165,7 @@ TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) {
} }
for (const Candidate& candidate : candidates) { for (const Candidate& candidate : candidates) {
// Expect only relay candidates now that the filter is applied. // Expect only relay candidates now that the filter is applied.
EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); EXPECT_TRUE(candidate.is_relay());
// Expect that the raddr is emptied due to the CF_RELAY filter. // Expect that the raddr is emptied due to the CF_RELAY filter.
EXPECT_EQ(candidate.related_address(), EXPECT_EQ(candidate.related_address(),
rtc::EmptySocketAddressWithFamily(candidate.address().family())); rtc::EmptySocketAddressWithFamily(candidate.address().family()));
@ -2210,21 +2201,21 @@ TEST_F(BasicPortAllocatorTest,
session_->SetCandidateFilter(CF_RELAY); session_->SetCandidateFilter(CF_RELAY);
ASSERT_EQ_SIMULATED_WAIT(1u, candidates_.size(), kDefaultAllocationTimeout, ASSERT_EQ_SIMULATED_WAIT(1u, candidates_.size(), kDefaultAllocationTimeout,
fake_clock); fake_clock);
EXPECT_EQ(RELAY_PORT_TYPE, candidates_.back().type()); EXPECT_TRUE(candidates_.back().is_relay());
EXPECT_EQ(1u, ports_.size()); EXPECT_EQ(1u, ports_.size());
// Surface the srflx candidate previously gathered but not signaled. // Surface the srflx candidate previously gathered but not signaled.
session_->SetCandidateFilter(CF_RELAY | CF_REFLEXIVE); session_->SetCandidateFilter(CF_RELAY | CF_REFLEXIVE);
ASSERT_EQ_SIMULATED_WAIT(2u, candidates_.size(), kDefaultAllocationTimeout, ASSERT_EQ_SIMULATED_WAIT(2u, candidates_.size(), kDefaultAllocationTimeout,
fake_clock); fake_clock);
EXPECT_EQ(STUN_PORT_TYPE, candidates_.back().type()); EXPECT_TRUE(candidates_.back().is_stun());
EXPECT_EQ(2u, ports_.size()); EXPECT_EQ(2u, ports_.size());
// Surface the srflx candidate previously gathered but not signaled. // Surface the srflx candidate previously gathered but not signaled.
session_->SetCandidateFilter(CF_ALL); session_->SetCandidateFilter(CF_ALL);
ASSERT_EQ_SIMULATED_WAIT(3u, candidates_.size(), kDefaultAllocationTimeout, ASSERT_EQ_SIMULATED_WAIT(3u, candidates_.size(), kDefaultAllocationTimeout,
fake_clock); fake_clock);
EXPECT_EQ(LOCAL_PORT_TYPE, candidates_.back().type()); EXPECT_TRUE(candidates_.back().is_local());
EXPECT_EQ(2u, ports_.size()); EXPECT_EQ(2u, ports_.size());
} }
@ -2260,21 +2251,21 @@ TEST_F(
session_->SetCandidateFilter(CF_RELAY); session_->SetCandidateFilter(CF_RELAY);
EXPECT_EQ_SIMULATED_WAIT(1u, candidates_.size(), kDefaultAllocationTimeout, EXPECT_EQ_SIMULATED_WAIT(1u, candidates_.size(), kDefaultAllocationTimeout,
fake_clock); fake_clock);
EXPECT_EQ(RELAY_PORT_TYPE, candidates_.back().type()); EXPECT_TRUE(candidates_.back().is_relay());
EXPECT_EQ(1u, ports_.size()); EXPECT_EQ(1u, ports_.size());
// Surface the srflx candidate previously gathered but not signaled. // Surface the srflx candidate previously gathered but not signaled.
session_->SetCandidateFilter(CF_REFLEXIVE); session_->SetCandidateFilter(CF_REFLEXIVE);
EXPECT_EQ_SIMULATED_WAIT(2u, candidates_.size(), kDefaultAllocationTimeout, EXPECT_EQ_SIMULATED_WAIT(2u, candidates_.size(), kDefaultAllocationTimeout,
fake_clock); fake_clock);
EXPECT_EQ(STUN_PORT_TYPE, candidates_.back().type()); EXPECT_TRUE(candidates_.back().is_stun());
EXPECT_EQ(2u, ports_.size()); EXPECT_EQ(2u, ports_.size());
// Surface the host candidate previously gathered but not signaled. // Surface the host candidate previously gathered but not signaled.
session_->SetCandidateFilter(CF_HOST); session_->SetCandidateFilter(CF_HOST);
EXPECT_EQ_SIMULATED_WAIT(3u, candidates_.size(), kDefaultAllocationTimeout, EXPECT_EQ_SIMULATED_WAIT(3u, candidates_.size(), kDefaultAllocationTimeout,
fake_clock); fake_clock);
EXPECT_EQ(LOCAL_PORT_TYPE, candidates_.back().type()); EXPECT_TRUE(candidates_.back().is_local());
// We use a shared socket and cricket::UDPPort handles the srflx candidate. // We use a shared socket and cricket::UDPPort handles the srflx candidate.
EXPECT_EQ(2u, ports_.size()); EXPECT_EQ(2u, ports_.size());
} }

View File

@ -1214,7 +1214,7 @@ void JsepTransportController::OnTransportCandidateGathered_n(
cricket::IceTransportInternal* transport, cricket::IceTransportInternal* transport,
const cricket::Candidate& candidate) { const cricket::Candidate& candidate) {
// We should never signal peer-reflexive candidates. // We should never signal peer-reflexive candidates.
if (candidate.type() == cricket::PRFLX_PORT_TYPE) { if (candidate.is_prflx()) {
RTC_DCHECK_NOTREACHED(); RTC_DCHECK_NOTREACHED();
return; return;
} }

View File

@ -104,13 +104,7 @@ uint32_t ConvertIceTransportTypeToCandidateFilter(
IceCandidatePairType GetIceCandidatePairCounter( IceCandidatePairType GetIceCandidatePairCounter(
const cricket::Candidate& local, const cricket::Candidate& local,
const cricket::Candidate& remote) { const cricket::Candidate& remote) {
const auto& l = local.type(); if (local.is_local() && remote.is_local()) {
const auto& r = remote.type();
const auto& host = cricket::LOCAL_PORT_TYPE;
const auto& srflx = cricket::STUN_PORT_TYPE;
const auto& relay = cricket::RELAY_PORT_TYPE;
const auto& prflx = cricket::PRFLX_PORT_TYPE;
if (l == host && r == host) {
bool local_hostname = bool local_hostname =
!local.address().hostname().empty() && local.address().IsUnresolvedIP(); !local.address().hostname().empty() && local.address().IsUnresolvedIP();
bool remote_hostname = !remote.address().hostname().empty() && bool remote_hostname = !remote.address().hostname().empty() &&
@ -143,34 +137,41 @@ IceCandidatePairType GetIceCandidatePairCounter(
} }
} }
} }
if (l == host && r == srflx)
return kIceCandidatePairHostSrflx; if (local.is_local()) {
if (l == host && r == relay) if (remote.is_stun())
return kIceCandidatePairHostRelay; return kIceCandidatePairHostSrflx;
if (l == host && r == prflx) if (remote.is_relay())
return kIceCandidatePairHostPrflx; return kIceCandidatePairHostRelay;
if (l == srflx && r == host) if (remote.is_prflx())
return kIceCandidatePairSrflxHost; return kIceCandidatePairHostPrflx;
if (l == srflx && r == srflx) } else if (local.is_stun()) {
return kIceCandidatePairSrflxSrflx; if (remote.is_local())
if (l == srflx && r == relay) return kIceCandidatePairSrflxHost;
return kIceCandidatePairSrflxRelay; if (remote.is_stun())
if (l == srflx && r == prflx) return kIceCandidatePairSrflxSrflx;
return kIceCandidatePairSrflxPrflx; if (remote.is_relay())
if (l == relay && r == host) return kIceCandidatePairSrflxRelay;
return kIceCandidatePairRelayHost; if (remote.is_prflx())
if (l == relay && r == srflx) return kIceCandidatePairSrflxPrflx;
return kIceCandidatePairRelaySrflx; } else if (local.is_relay()) {
if (l == relay && r == relay) if (remote.is_local())
return kIceCandidatePairRelayRelay; return kIceCandidatePairRelayHost;
if (l == relay && r == prflx) if (remote.is_stun())
return kIceCandidatePairRelayPrflx; return kIceCandidatePairRelaySrflx;
if (l == prflx && r == host) if (remote.is_relay())
return kIceCandidatePairPrflxHost; return kIceCandidatePairRelayRelay;
if (l == prflx && r == srflx) if (remote.is_prflx())
return kIceCandidatePairPrflxSrflx; return kIceCandidatePairRelayPrflx;
if (l == prflx && r == relay) } else if (local.is_prflx()) {
return kIceCandidatePairPrflxRelay; if (remote.is_local())
return kIceCandidatePairPrflxHost;
if (remote.is_stun())
return kIceCandidatePairPrflxSrflx;
if (remote.is_relay())
return kIceCandidatePairPrflxRelay;
}
return kIceCandidatePairMax; return kIceCandidatePairMax;
} }

View File

@ -3087,25 +3087,23 @@ TEST_P(PeerConnectionIntegrationTest, RegatherAfterChangingIceTransportType) {
// `WebRTC.PeerConnection.CandidatePairType_UDP` in this test since this // `WebRTC.PeerConnection.CandidatePairType_UDP` in this test since this
// metric is only populated when we reach kIceConnectionComplete in the // metric is only populated when we reach kIceConnectionComplete in the
// current implementation. // current implementation.
EXPECT_EQ(cricket::RELAY_PORT_TYPE, EXPECT_TRUE(caller()->last_candidate_gathered().is_relay());
caller()->last_candidate_gathered().type()); EXPECT_TRUE(callee()->last_candidate_gathered().is_relay());
EXPECT_EQ(cricket::RELAY_PORT_TYPE,
callee()->last_candidate_gathered().type());
// Loosen the caller's candidate filter. // Loosen the caller's candidate filter.
caller_config = caller()->pc()->GetConfiguration(); caller_config = caller()->pc()->GetConfiguration();
caller_config.type = PeerConnectionInterface::kAll; caller_config.type = PeerConnectionInterface::kAll;
caller()->pc()->SetConfiguration(caller_config); caller()->pc()->SetConfiguration(caller_config);
// We should have gathered a new host candidate. // We should have gathered a new host candidate.
EXPECT_EQ_WAIT(cricket::LOCAL_PORT_TYPE, EXPECT_TRUE_WAIT(caller()->last_candidate_gathered().is_local(),
caller()->last_candidate_gathered().type(), kDefaultTimeout); kDefaultTimeout);
// Loosen the callee's candidate filter. // Loosen the callee's candidate filter.
callee_config = callee()->pc()->GetConfiguration(); callee_config = callee()->pc()->GetConfiguration();
callee_config.type = PeerConnectionInterface::kAll; callee_config.type = PeerConnectionInterface::kAll;
callee()->pc()->SetConfiguration(callee_config); callee()->pc()->SetConfiguration(callee_config);
EXPECT_EQ_WAIT(cricket::LOCAL_PORT_TYPE, EXPECT_TRUE_WAIT(callee()->last_candidate_gathered().is_local(),
callee()->last_candidate_gathered().type(), kDefaultTimeout); kDefaultTimeout);
// Create an offer and verify that it does not contain an ICE restart (i.e new // Create an offer and verify that it does not contain an ICE restart (i.e new
// ice credentials). // ice credentials).

View File

@ -961,12 +961,10 @@ const std::string& ProduceIceCandidateStats(Timestamp timestamp,
if (is_local) { if (is_local) {
candidate_stats->network_type = candidate_stats->network_type =
NetworkTypeToStatsType(candidate.network_type()); NetworkTypeToStatsType(candidate.network_type());
const std::string& candidate_type = candidate.type();
const std::string& relay_protocol = candidate.relay_protocol(); const std::string& relay_protocol = candidate.relay_protocol();
const std::string& url = candidate.url(); const std::string& url = candidate.url();
if (candidate_type == cricket::RELAY_PORT_TYPE || if (candidate.is_relay() ||
(candidate_type == cricket::PRFLX_PORT_TYPE && (candidate.is_prflx() && !relay_protocol.empty())) {
!relay_protocol.empty())) {
RTC_DCHECK(relay_protocol.compare("udp") == 0 || RTC_DCHECK(relay_protocol.compare("udp") == 0 ||
relay_protocol.compare("tcp") == 0 || relay_protocol.compare("tcp") == 0 ||
relay_protocol.compare("tls") == 0); relay_protocol.compare("tls") == 0);
@ -974,7 +972,7 @@ const std::string& ProduceIceCandidateStats(Timestamp timestamp,
if (!url.empty()) { if (!url.empty()) {
candidate_stats->url = url; candidate_stats->url = url;
} }
} else if (candidate_type == cricket::STUN_PORT_TYPE) { } else if (candidate.is_stun()) {
if (!url.empty()) { if (!url.empty()) {
candidate_stats->url = url; candidate_stats->url = url;
} }