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;
bool IsRelayRelay(const cricket::Connection* conn) {
return conn->local_candidate().type() == cricket::RELAY_PORT_TYPE &&
conn->remote_candidate().type() == cricket::RELAY_PORT_TYPE;
return conn->local_candidate().is_relay() &&
conn->remote_candidate().is_relay();
}
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
// enum.
webrtc::IceCandidateType GetCandidateTypeByString(absl::string_view type) {
if (type == LOCAL_PORT_TYPE) {
webrtc::IceCandidateType GetRtcEventLogCandidateType(const Candidate& c) {
if (c.is_local()) {
return webrtc::IceCandidateType::kLocal;
} else if (type == STUN_PORT_TYPE) {
} else if (c.is_stun()) {
return webrtc::IceCandidateType::kStun;
} else if (type == PRFLX_PORT_TYPE) {
} else if (c.is_prflx()) {
return webrtc::IceCandidateType::kPrflx;
} else if (type == RELAY_PORT_TYPE) {
} else if (c.is_relay()) {
return webrtc::IceCandidateType::kRelay;
}
return webrtc::IceCandidateType::kUnknown;
@ -1367,15 +1367,13 @@ const webrtc::IceCandidatePairDescription& Connection::ToLogDescription() {
const Candidate& remote = remote_candidate();
const rtc::Network* network = port()->Network();
log_description_ = webrtc::IceCandidatePairDescription();
log_description_->local_candidate_type =
GetCandidateTypeByString(local.type());
log_description_->local_candidate_type = GetRtcEventLogCandidateType(local);
log_description_->local_relay_protocol =
GetProtocolByString(local.relay_protocol());
log_description_->local_network_type = ConvertNetworkType(network->type());
log_description_->local_address_family =
GetAddressFamilyByInt(local.address().family());
log_description_->remote_candidate_type =
GetCandidateTypeByString(remote.type());
log_description_->remote_candidate_type = GetRtcEventLogCandidateType(remote);
log_description_->remote_address_family =
GetAddressFamilyByInt(remote.address().family());
log_description_->candidate_pair_protocol =

View File

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

View File

@ -259,14 +259,18 @@ void Port::AddAddress(const rtc::SocketAddress& address,
absl::string_view url,
bool is_final) {
RTC_DCHECK_RUN_ON(thread_);
if (protocol == TCP_PROTOCOL_NAME && type == LOCAL_PORT_TYPE) {
RTC_DCHECK(!tcptype.empty());
}
std::string foundation =
ComputeFoundation(type, protocol, relay_protocol, base_address);
Candidate c(component_, protocol, address, 0U, username_fragment(), password_,
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_priority(
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_related_address(related_address);
bool pending = MaybeObfuscateAddress(&c, type, is_final);
bool pending = MaybeObfuscateAddress(c, is_final);
if (!pending) {
FinishAddingAddress(c, is_final);
}
}
bool Port::MaybeObfuscateAddress(Candidate* c,
absl::string_view type,
bool is_final) {
bool Port::MaybeObfuscateAddress(const Candidate& c, bool is_final) {
// TODO(bugs.webrtc.org/9723): Use a config to control the feature of IP
// handling with mDNS.
if (network_->GetMdnsResponder() == nullptr) {
return false;
}
if (type != LOCAL_PORT_TYPE) {
if (!c.is_local()) {
return false;
}
auto copy = *c;
auto copy = c;
auto weak_ptr = weak_factory_.GetWeakPtr();
auto callback = [weak_ptr, copy, is_final](const rtc::IPAddress& addr,
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
// 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
// conflit in the value of the 2-tuple, make sure that the implementation that
// relies on this 2-tuple for RTTI is properly changed.
// conflict in the value of the 2-tuple, make sure that the implementation
// that relies on this 2-tuple for RTTI is properly changed.
const absl::string_view Type() const override;
const rtc::Network* Network() const override;
@ -525,9 +525,8 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> {
webrtc::FieldTrialBasedConfig>
field_trials_;
bool MaybeObfuscateAddress(Candidate* c,
absl::string_view type,
bool is_final) RTC_RUN_ON(thread_);
bool MaybeObfuscateAddress(const Candidate& c, bool is_final)
RTC_RUN_ON(thread_);
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);
ASSERT_EQ(1U, port()->Candidates().size());
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

View File

@ -134,8 +134,7 @@ Connection* TCPPort::CreateConnection(const Candidate& address,
return NULL;
}
if ((address.tcptype() == TCPTYPE_ACTIVE_STR &&
address.type() != PRFLX_PORT_TYPE) ||
if ((address.tcptype() == TCPTYPE_ACTIVE_STR && !address.is_prflx()) ||
(address.tcptype().empty() && address.address().port() == 0)) {
// It's active only candidate, we should not try to create connections
// 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.
static bool FindCandidate(const std::vector<Candidate>& candidates,
absl::string_view type,
@ -1237,7 +1226,7 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) {
int num_nonrelay_candidates = 0;
for (const Candidate& candidate : candidates_) {
// 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));
++num_nonrelay_candidates;
}
@ -1272,9 +1261,11 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoAdapters) {
rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)));
// Again, two TURN candidates, using UDP/TCP for the first hop to the TURN
// server.
EXPECT_EQ(2,
CountCandidates(candidates_, "relay", "udp",
rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)));
rtc::SocketAddress addr(kTurnUdpExtAddr.ipaddr(), 0);
EXPECT_EQ(2, absl::c_count_if(candidates_, [&](const Candidate& c) {
return c.is_relay() && c.protocol() == "udp" &&
AddressMatch(c.address(), addr);
}));
}
// 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, 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(
candidates_[0].related_address(),
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, ports_.size()); // UDP/TCP ports only.
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.
EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate.
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(
candidates_[0].related_address(),
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, ports_.size()); // UDP and TCP ports will be in ready state.
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) {
// 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_EQ(candidate.related_address(),
rtc::EmptySocketAddressWithFamily(candidate.address().family()));
@ -2210,21 +2201,21 @@ TEST_F(BasicPortAllocatorTest,
session_->SetCandidateFilter(CF_RELAY);
ASSERT_EQ_SIMULATED_WAIT(1u, candidates_.size(), kDefaultAllocationTimeout,
fake_clock);
EXPECT_EQ(RELAY_PORT_TYPE, candidates_.back().type());
EXPECT_TRUE(candidates_.back().is_relay());
EXPECT_EQ(1u, ports_.size());
// Surface the srflx candidate previously gathered but not signaled.
session_->SetCandidateFilter(CF_RELAY | CF_REFLEXIVE);
ASSERT_EQ_SIMULATED_WAIT(2u, candidates_.size(), kDefaultAllocationTimeout,
fake_clock);
EXPECT_EQ(STUN_PORT_TYPE, candidates_.back().type());
EXPECT_TRUE(candidates_.back().is_stun());
EXPECT_EQ(2u, ports_.size());
// Surface the srflx candidate previously gathered but not signaled.
session_->SetCandidateFilter(CF_ALL);
ASSERT_EQ_SIMULATED_WAIT(3u, candidates_.size(), kDefaultAllocationTimeout,
fake_clock);
EXPECT_EQ(LOCAL_PORT_TYPE, candidates_.back().type());
EXPECT_TRUE(candidates_.back().is_local());
EXPECT_EQ(2u, ports_.size());
}
@ -2260,21 +2251,21 @@ TEST_F(
session_->SetCandidateFilter(CF_RELAY);
EXPECT_EQ_SIMULATED_WAIT(1u, candidates_.size(), kDefaultAllocationTimeout,
fake_clock);
EXPECT_EQ(RELAY_PORT_TYPE, candidates_.back().type());
EXPECT_TRUE(candidates_.back().is_relay());
EXPECT_EQ(1u, ports_.size());
// Surface the srflx candidate previously gathered but not signaled.
session_->SetCandidateFilter(CF_REFLEXIVE);
EXPECT_EQ_SIMULATED_WAIT(2u, candidates_.size(), kDefaultAllocationTimeout,
fake_clock);
EXPECT_EQ(STUN_PORT_TYPE, candidates_.back().type());
EXPECT_TRUE(candidates_.back().is_stun());
EXPECT_EQ(2u, ports_.size());
// Surface the host candidate previously gathered but not signaled.
session_->SetCandidateFilter(CF_HOST);
EXPECT_EQ_SIMULATED_WAIT(3u, candidates_.size(), kDefaultAllocationTimeout,
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.
EXPECT_EQ(2u, ports_.size());
}

View File

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

View File

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

View File

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

View File

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