Reland "Deprecate old constructors and set_type() in Candidate and Port"

This reverts commit ed8390d21a7b15091d01bc8e843193d0a6efd23a.

Reason for revert: Fix has landed in chrome, ready to reland.

Original change's description:
> Revert "Deprecate old constructors and set_type() in Candidate and Port"
>
> This reverts commit aaa6851d53741179a591d79fc82c4dd6651a7ba5.
>
> Reason for revert: breaks chromium webrtc import
>
> Original change's description:
> > Deprecate old constructors and set_type() in Candidate and Port
> >
> > * Deprecates constructors that use string based `type`
> > * Deprecates string based type functions in favor of enum based.
> > * Restrict possible values of Candidate::type. Ensure a valid value
> >   is assigned at construction.
> > * Make Port constructors protected to limit their use to subclasses.
> >   - The reason for this is to make sure that use of SharedSocket()
> >     is controlled (it adds a bit of complexity).
> > * Simplify construction of Port (remove Construct() etc)
> >
> > Bug: webrtc:15846
> > Change-Id: If24ed674e175642efa49da37fd2bc847dd14f613
> > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/339860
> > Reviewed-by: Harald Alvestrand <hta@webrtc.org>
> > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
> > Cr-Commit-Position: refs/heads/main@{#41865}
>
> Bug: webrtc:15846
> Change-Id: Ic8b7cba97f8fb207ef51a88900e704658ade28b7
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/342140
> Auto-Submit: Ilya Nikolaevskiy <ilnik@webrtc.org>
> Owners-Override: Ilya Nikolaevskiy <ilnik@webrtc.org>
> Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
> Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
> Cr-Commit-Position: refs/heads/main@{#41867}

Bug: webrtc:15846
Change-Id: I3d52643bbb537d1c072643528828d26eb18fea94
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/342200
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41875}
This commit is contained in:
Tomas Gunnarsson 2024-03-07 15:24:55 +00:00 committed by WebRTC LUCI CQ
parent 17e358096e
commit 0242939296
22 changed files with 425 additions and 291 deletions

View File

@ -57,18 +57,18 @@ class RTC_EXPORT Candidate {
absl::string_view foundation,
uint16_t network_id = 0,
uint16_t network_cost = 0);
// TODO(tommi): Deprecate.
Candidate(int component,
absl::string_view protocol,
const rtc::SocketAddress& address,
uint32_t priority,
absl::string_view username,
absl::string_view password,
absl::string_view type ABSL_ATTRIBUTE_LIFETIME_BOUND,
uint32_t generation,
absl::string_view foundation,
uint16_t network_id = 0,
uint16_t network_cost = 0);
[[deprecated("Use IceCandidateType version")]] Candidate(
int component,
absl::string_view protocol,
const rtc::SocketAddress& address,
uint32_t priority,
absl::string_view username,
absl::string_view password,
absl::string_view type ABSL_ATTRIBUTE_LIFETIME_BOUND,
uint32_t generation,
absl::string_view foundation,
uint16_t network_id = 0,
uint16_t network_cost = 0);
Candidate(const Candidate&);
~Candidate();
@ -77,7 +77,10 @@ class RTC_EXPORT Candidate {
// Generates a new, 8 character long, id.
void generate_id();
// TODO(tommi): Callers should use generate_id(). Remove.
[[deprecated]] void set_id(absl::string_view id) { Assign(id_, id); }
[[deprecated("Use IceCandidateType version")]] void set_id(
absl::string_view id) {
Assign(id_, id);
}
int component() const { return component_; }
void set_component(int component) { component_ = component; }
@ -124,8 +127,8 @@ class RTC_EXPORT Candidate {
// things down. See also the `Port` class.
void set_type(webrtc::IceCandidateType type) { type_ = type; }
// TODO(tommi): Deprecate.
void set_type(absl::string_view type ABSL_ATTRIBUTE_LIFETIME_BOUND);
[[deprecated("Use IceCandidateType version")]] void set_type(
absl::string_view type ABSL_ATTRIBUTE_LIFETIME_BOUND);
// Simple checkers for checking the candidate type without dependency on the
// IceCandidateType enum. The `is_local()` and `is_stun()` names are legacy

View File

@ -43,6 +43,8 @@
namespace cricket {
namespace {
using webrtc::IceCandidateType;
// Determines whether we have seen at least the given maximum number of
// pings fail to have a response.
inline bool TooManyFailures(
@ -75,16 +77,16 @@ inline bool TooLongWithoutResponse(
// Helper methods for converting string values of log description fields to
// enum.
webrtc::IceCandidateType GetRtcEventLogCandidateType(const Candidate& c) {
IceCandidateType GetRtcEventLogCandidateType(const Candidate& c) {
if (c.is_local()) {
return webrtc::IceCandidateType::kHost;
return IceCandidateType::kHost;
} else if (c.is_stun()) {
return webrtc::IceCandidateType::kSrflx;
return IceCandidateType::kSrflx;
} else if (c.is_prflx()) {
return webrtc::IceCandidateType::kPrflx;
return IceCandidateType::kPrflx;
}
RTC_DCHECK(c.is_relay());
return webrtc::IceCandidateType::kRelay;
return IceCandidateType::kRelay;
}
webrtc::IceCandidatePairProtocol GetProtocolByString(
@ -1692,7 +1694,7 @@ void Connection::MaybeUpdateLocalCandidate(StunRequest* request,
// Create a peer-reflexive candidate based on the local candidate.
local_candidate_.generate_id();
local_candidate_.set_type(PRFLX_PORT_TYPE);
local_candidate_.set_type(IceCandidateType::kPrflx);
// Set the related address and foundation attributes before changing the
// address.
local_candidate_.set_related_address(local_candidate_.address());

View File

@ -64,7 +64,7 @@ class TestUDPPort : public UDPPort {
bool emit_localhost_for_anyaddress,
const webrtc::FieldTrialsView* field_trials)
: UDPPort(thread,
LOCAL_PORT_TYPE,
webrtc::IceCandidateType::kHost,
factory,
network,
min_port,

View File

@ -53,18 +53,6 @@ using ::webrtc::RTCErrorType;
using ::webrtc::SafeTask;
using ::webrtc::TimeDelta;
IceCandidateType PortTypeToIceCandidateType(PortInterface* port) {
auto type = port->Type();
if (type == LOCAL_PORT_TYPE)
return IceCandidateType::kHost;
if (type == STUN_PORT_TYPE)
return IceCandidateType::kSrflx;
if (type == PRFLX_PORT_TYPE)
return IceCandidateType::kPrflx;
RTC_DCHECK_EQ(type, RELAY_PORT_TYPE);
return IceCandidateType::kRelay;
}
cricket::PortInterface::CandidateOrigin GetOrigin(
cricket::PortInterface* port,
cricket::PortInterface* origin_port) {
@ -1083,8 +1071,8 @@ void P2PTransportChannel::OnUnknownAddress(PortInterface* port,
// candidate.
remote_candidate = Candidate(
component(), ProtoToString(proto), address, remote_candidate_priority,
remote_username, remote_password, PRFLX_PORT_TYPE, remote_generation,
"", network_id, network_cost);
remote_username, remote_password, IceCandidateType::kPrflx,
remote_generation, "", network_id, network_cost);
if (proto == PROTO_TCP) {
remote_candidate.set_tcptype(TCPTYPE_ACTIVE_STR);
}
@ -1422,12 +1410,12 @@ bool P2PTransportChannel::CreateConnection(PortInterface* port,
}
if (ice_field_trials_.skip_relay_to_non_relay_connections) {
IceCandidateType port_type = PortTypeToIceCandidateType(port);
IceCandidateType port_type = PortTypeToIceCandidateType(port->Type());
if ((port_type != remote_candidate.type()) &&
(port_type == IceCandidateType::kRelay ||
remote_candidate.is_relay())) {
RTC_LOG(LS_INFO) << ToString() << ": skip creating connection "
<< port->Type() << " to "
<< webrtc::IceCandidateTypeToString(port_type) << " to "
<< remote_candidate.type_name();
return false;
}

View File

@ -154,7 +154,7 @@ cricket::IceConfig CreateIceConfig(
return config;
}
cricket::Candidate CreateUdpCandidate(absl::string_view type,
cricket::Candidate CreateUdpCandidate(IceCandidateType type,
absl::string_view ip,
int port,
int priority,
@ -2128,9 +2128,9 @@ TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) {
// Add two remote candidates; a host candidate (with higher priority)
// and TURN candidate.
ep1_ch1()->AddRemoteCandidate(
CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 100));
ep1_ch1()->AddRemoteCandidate(
CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 0));
CreateUdpCandidate(IceCandidateType::kRelay, "2.2.2.2", 2, 0));
// Expect that the TURN-TURN candidate pair will be prioritized since it's
// "probably writable".
EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() != nullptr, kShortTimeout);
@ -2226,7 +2226,7 @@ TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) {
// Add a remote TURN candidate. The first channel should still have a TURN
// 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));
CreateUdpCandidate(IceCandidateType::kRelay, "2.2.2.2", 2, 0));
EXPECT_TRUE(LocalCandidate(ep1_ch1())->is_relay());
EXPECT_TRUE(RemoteCandidate(ep1_ch1())->is_relay());
EXPECT_TRUE(ep1_ch1()->writable());
@ -2252,7 +2252,7 @@ TEST_F(P2PTransportChannelTest, SignalReadyToSendWithPresumedWritable) {
EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete,
ep1_ch1()->gathering_state(), kDefaultTimeout);
ep1_ch1()->AddRemoteCandidate(
CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 0));
CreateUdpCandidate(IceCandidateType::kRelay, "1.1.1.1", 1, 0));
// Sanity checking the type of the connection.
EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() != nullptr, kShortTimeout);
EXPECT_TRUE(LocalCandidate(ep1_ch1())->is_relay());
@ -3422,7 +3422,7 @@ class P2PTransportChannelPingTest : public ::testing::Test,
int priority,
bool writable) {
channel->AddRemoteCandidate(
CreateUdpCandidate(LOCAL_PORT_TYPE, ip_addr, port, priority));
CreateUdpCandidate(IceCandidateType::kHost, ip_addr, port, priority));
EXPECT_TRUE_SIMULATED_WAIT(
GetConnectionTo(channel, ip_addr, port) != nullptr, kMediumTimeout,
*clock);
@ -3567,8 +3567,10 @@ TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) {
P2PTransportChannel ch("trigger checks", 1, &pa, &field_trials_);
PrepareChannel(&ch);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 2));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
@ -3592,8 +3594,10 @@ TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) {
P2PTransportChannel ch("ping sufficiently", 1, &pa, &field_trials_);
PrepareChannel(&ch);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 2));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
@ -3621,7 +3625,8 @@ TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) {
P2PTransportChannel ch("TestChannel", 1, &pa, &field_trials_);
PrepareChannel(&ch);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn != nullptr);
@ -3750,8 +3755,10 @@ TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
P2PTransportChannel ch("trigger checks", 1, &pa, &field_trials_);
PrepareChannel(&ch);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 2));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
@ -3777,7 +3784,8 @@ TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) {
&field_trials_);
PrepareChannel(&ch);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
@ -3795,7 +3803,8 @@ TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) {
P2PTransportChannel ch("state change", 1, &pa, &field_trials_);
PrepareChannel(&ch);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
// Pruning the connection reduces the set of active connections and changes
@ -3818,8 +3827,8 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
PrepareChannel(&ch);
ch.MaybeStartGathering();
// Add a candidate with a future ufrag.
ch.AddRemoteCandidate(
CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2]));
ch.AddRemoteCandidate(CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1",
1, 1, kIceUfrag[2]));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
const Candidate& candidate = conn1->remote_candidate();
@ -3836,15 +3845,15 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
// Add a candidate with an old ufrag. No connection will be created.
ch.AddRemoteCandidate(
CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2, kIceUfrag[1]));
ch.AddRemoteCandidate(CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2",
2, 2, kIceUfrag[1]));
rtc::Thread::Current()->ProcessMessages(500);
EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr);
// Add a candidate with the current ufrag, its pwd and generation will be
// assigned, even if the generation is not set.
ch.AddRemoteCandidate(
CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 0, kIceUfrag[2]));
ch.AddRemoteCandidate(CreateUdpCandidate(IceCandidateType::kHost, "3.3.3.3",
3, 0, kIceUfrag[2]));
Connection* conn3 = nullptr;
ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr,
kMediumTimeout);
@ -3872,14 +3881,16 @@ TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
ch.MaybeStartGathering();
// Create conn1 and keep track of original candidate priority.
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
uint32_t remote_priority = conn1->remote_candidate().priority();
// Create a higher priority candidate and make the connection
// receiving/writable. This will prune conn1.
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 2));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing();
@ -3931,7 +3942,8 @@ TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) {
EXPECT_EQ(500, ch.config().receiving_timeout_or_default());
EXPECT_EQ(50, ch.check_receiving_interval());
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
ASSERT_TRUE(conn1 != nullptr);
@ -3957,7 +3969,8 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
// Channel is not ready to send because it is not writable.
@ -3978,7 +3991,8 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
// When a higher priority candidate comes in, the new connection is chosen
// as the selected connection.
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 10));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPingResponse(LOW_RTT, "id");
@ -3993,7 +4007,8 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
// connection will be set as the selected connection, even though
// its priority is lower.
EXPECT_EQ(len, SendData(&ch, data, len, ++last_packet_id));
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "3.3.3.3", 3, 1));
Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
// Because it has a lower priority, the selected connection is still conn2.
@ -4014,7 +4029,8 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
// the selected connection because the selected connection is nominated by
// the controlling side.
EXPECT_EQ(len, SendData(&ch, data, len, ++last_packet_id));
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "4.4.4.4", 4, 100));
Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
ASSERT_TRUE(conn4 != nullptr);
EXPECT_EQ(conn3, ch.selected_connection());
@ -4049,7 +4065,8 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnNomination) {
ch.SetIceConfig(ch.config());
ch.SetIceRole(ICEROLE_CONTROLLED);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
@ -4060,7 +4077,8 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnNomination) {
// When a higher priority candidate comes in, the new connection is chosen
// as the selected connection.
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 10));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPingResponse(LOW_RTT, "id");
@ -4091,7 +4109,8 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnSwitch) {
ch.SetIceConfig(ch.config());
ch.SetIceRole(ICEROLE_CONTROLLING);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
@ -4102,7 +4121,8 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnSwitch) {
// When a higher priority candidate comes in, the new connection is chosen
// as the selected connection.
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 10));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
@ -4130,7 +4150,8 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnSelected) {
ch.SetIceConfig(ch.config());
ch.SetIceRole(ICEROLE_CONTROLLING);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
@ -4176,7 +4197,8 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout);
// Another connection is nominated via use_candidate.
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 1));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
// Because it has a lower priority, the selected connection is still conn1.
@ -4236,7 +4258,8 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 10));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 10));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
conn1->ReceivedPingResponse(LOW_RTT, "id");
@ -4245,7 +4268,8 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
// If a data packet is received on conn2, the selected connection should
// switch to conn2 because the controlled side must mirror the media path
// chosen by the controlling side.
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 1));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable and receiving.
@ -4561,8 +4585,8 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) {
const int port_num = 1;
// kIceUfrag[1] is the current generation ufrag.
Candidate candidate = CreateUdpCandidate(LOCAL_PORT_TYPE, host_address,
port_num, 1, kIceUfrag[1]);
Candidate candidate = CreateUdpCandidate(
IceCandidateType::kHost, host_address, port_num, 1, kIceUfrag[1]);
ch.AddRemoteCandidate(candidate);
Connection* conn1 = WaitForConnectionTo(&ch, host_address, port_num);
ASSERT_TRUE(conn1 != nullptr);
@ -4599,7 +4623,8 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(nullptr, ch.selected_connection());
@ -4607,7 +4632,8 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
// When a higher-priority, nominated candidate comes in, the connections with
// lower-priority are pruned.
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 10));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
@ -4618,7 +4644,8 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
// Wait until conn2 becomes not receiving.
EXPECT_TRUE_SIMULATED_WAIT(!conn2->receiving(), kMediumTimeout, clock);
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "3.3.3.3", 3, 1));
Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3, &clock);
ASSERT_TRUE(conn3 != nullptr);
// The selected connection should still be conn2. Even through conn3 has lower
@ -4666,8 +4693,10 @@ TEST_F(P2PTransportChannelPingTest, TestGetState) {
// any connections yet.
EXPECT_EQ(webrtc::IceTransportState::kNew, ch.GetIceTransportState());
EXPECT_EQ(IceTransportState::STATE_INIT, ch.GetState());
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 100));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 1));
// Checking candidates that have been added with gathered candidates.
ASSERT_GT(ch.connections().size(), 0u);
EXPECT_EQ(webrtc::IceTransportState::kChecking, ch.GetIceTransportState());
@ -4706,7 +4735,8 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
config.receiving_switching_delay = 800;
ch.SetIceConfig(config);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 100));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(nullptr, ch.selected_connection());
@ -4718,7 +4748,8 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
// not be deleted right away. Once the current selected connection becomes not
// receiving, `conn2` will start to ping and upon receiving the ping response,
// it will become the selected connection.
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 1));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock);
ASSERT_TRUE(conn2 != nullptr);
EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock);
@ -4755,7 +4786,8 @@ TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
PrepareChannel(&ch);
ch.MaybeStartGathering();
// Have one connection only but later becomes write-time-out.
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 100));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
ASSERT_TRUE(conn1 != nullptr);
conn1->ReceivedPing(); // Becomes receiving
@ -4763,11 +4795,13 @@ TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
EXPECT_TRUE_SIMULATED_WAIT(ch.connections().empty(), kShortTimeout, clock);
// Have two connections but both become write-time-out later.
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 1));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing(); // Becomes receiving
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 2));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "3.3.3.3", 3, 2));
Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3, &clock);
ASSERT_TRUE(conn3 != nullptr);
conn3->ReceivedPing(); // Becomes receiving
@ -4788,7 +4822,8 @@ TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
PrepareChannel(&ch);
ch.SetIceConfig(CreateIceConfig(2000, GATHER_ONCE));
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 100));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
@ -4805,7 +4840,8 @@ TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
// But if a new connection created from the new session becomes writable,
// it will stop the current session.
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 100));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
@ -4825,7 +4861,8 @@ TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) {
IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY);
ch.SetIceConfig(config);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn != nullptr);
@ -4850,7 +4887,8 @@ TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) {
// Starts with ICEROLE_CONTROLLING.
PrepareChannel(&ch);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn != nullptr);
@ -4876,7 +4914,8 @@ TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeoutAndPruned) {
PrepareChannel(&ch);
ch.SetIceRole(ICEROLE_CONTROLLED);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn != nullptr);
@ -4906,8 +4945,10 @@ TEST_F(P2PTransportChannelPingTest, TestMaxOutstandingPingsFieldTrial) {
ch.SetIceConfig(ch.config());
PrepareChannel(&ch);
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 2));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
@ -4993,8 +5034,10 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kRelay, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 2));
EXPECT_TRUE_WAIT(ch.connections().size() == 4, kDefaultTimeout);
@ -5052,7 +5095,8 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
EXPECT_TRUE_WAIT(ch.connections().size() == 2, kDefaultTimeout);
// Initially, only have Local/Local and Local/Relay.
@ -5062,7 +5106,8 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
IceCandidateType::kHost);
// Remote Relay candidate arrives.
ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 2));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kRelay, "2.2.2.2", 2, 2));
EXPECT_TRUE_WAIT(ch.connections().size() == 4, kDefaultTimeout);
// Relay/Relay should be the first since it hasn't been pinged before.
@ -5088,7 +5133,8 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kRelay, "1.1.1.1", 1, 1));
EXPECT_TRUE_WAIT(ch.connections().size() == 2, kDefaultTimeout);
// Initially, only have Relay/Relay and Local/Relay. Ping Relay/Relay first.
@ -5100,7 +5146,8 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
IceCandidateType::kRelay);
// Remote Local candidate arrives.
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 2));
EXPECT_TRUE_WAIT(ch.connections().size() == 4, kDefaultTimeout);
// Local/Local should be the first since it hasn't been pinged before.
@ -5130,11 +5177,13 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
// Remote Relay candidate arrives.
ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kRelay, "1.1.1.1", 1, 1));
EXPECT_TRUE_WAIT(ch.connections().size() == 1, kDefaultTimeout);
// Remote Local candidate arrives.
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 2));
EXPECT_TRUE_WAIT(ch.connections().size() == 2, kDefaultTimeout);
}
@ -5155,7 +5204,8 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestTcpTurn) {
EXPECT_EQ(ch.ports()[2]->Type(), RELAY_PORT_TYPE);
// Remote Relay candidate arrives.
ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kRelay, "1.1.1.1", 1, 1));
EXPECT_TRUE_WAIT(ch.connections().size() == 3, kDefaultTimeout);
// UDP Relay/Relay should be pinged first.
@ -5609,16 +5659,19 @@ TEST_F(P2PTransportChannelTest,
// host, srflx and relay types. Note that the candidates differ in their
// ports.
cricket::Candidate host_candidate = CreateUdpCandidate(
LOCAL_PORT_TYPE, "1.1.1.1", 1 /* port */, 0 /* priority */);
IceCandidateType::kHost, "1.1.1.1", 1 /* port */, 0 /* priority */);
ep1_ch1()->AddRemoteCandidate(host_candidate);
std::vector<cricket::Candidate> mdns_candidates;
mdns_candidates.push_back(CreateUdpCandidate(LOCAL_PORT_TYPE, "example.local",
2 /* port */, 0 /* priority */));
mdns_candidates.push_back(CreateUdpCandidate(STUN_PORT_TYPE, "example.local",
3 /* port */, 0 /* priority */));
mdns_candidates.push_back(CreateUdpCandidate(RELAY_PORT_TYPE, "example.local",
4 /* port */, 0 /* priority */));
mdns_candidates.push_back(CreateUdpCandidate(IceCandidateType::kHost,
"example.local", 2 /* port */,
0 /* priority */));
mdns_candidates.push_back(CreateUdpCandidate(IceCandidateType::kSrflx,
"example.local", 3 /* port */,
0 /* priority */));
mdns_candidates.push_back(CreateUdpCandidate(IceCandidateType::kRelay,
"example.local", 4 /* port */,
0 /* priority */));
// We just resolve the hostname to 1.1.1.1, and add the candidates with this
// address directly to simulate the process of adding remote candidates with
// the name resolution.
@ -5993,7 +6046,8 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampening0) {
ch.SetIceConfig(ch.config());
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 100));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(nullptr, ch.selected_connection());
@ -6018,7 +6072,8 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampening) {
ch.SetIceConfig(ch.config());
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 100));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(nullptr, ch.selected_connection());
@ -6044,7 +6099,8 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampeningPingReceived) {
ch.SetIceConfig(ch.config());
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 100));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(nullptr, ch.selected_connection());
@ -6073,7 +6129,8 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampeningBoth) {
ch.SetIceConfig(ch.config());
ch.MaybeStartGathering();
ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
ch.AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 100));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(nullptr, ch.selected_connection());
@ -6177,8 +6234,10 @@ TEST_F(P2PTransportChannelPingTest, TestForgetLearnedState) {
PrepareChannel(ch.get());
ch->MaybeStartGathering();
ch->AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
ch->AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
ch->AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1));
ch->AddRemoteCandidate(
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 2));
Connection* conn1 = WaitForConnectionTo(ch.get(), "1.1.1.1", 1);
Connection* conn2 = WaitForConnectionTo(ch.get(), "2.2.2.2", 2);
@ -6223,7 +6282,7 @@ TEST_F(P2PTransportChannelTest, DisableDnsLookupsWithTransportPolicyRelay) {
CreateChannels();
ep1_ch1()->AddRemoteCandidate(
CreateUdpCandidate(LOCAL_PORT_TYPE, "hostname.test", 1, 100));
CreateUdpCandidate(IceCandidateType::kHost, "hostname.test", 1, 100));
DestroyChannels();
}
@ -6249,7 +6308,7 @@ TEST_F(P2PTransportChannelTest, DisableDnsLookupsWithTransportPolicyNone) {
CreateChannels();
ep1_ch1()->AddRemoteCandidate(
CreateUdpCandidate(LOCAL_PORT_TYPE, "hostname.test", 1, 100));
CreateUdpCandidate(IceCandidateType::kHost, "hostname.test", 1, 100));
DestroyChannels();
}
@ -6276,7 +6335,7 @@ TEST_F(P2PTransportChannelTest, EnableDnsLookupsWithTransportPolicyNoHost) {
CreateChannels();
ep1_ch1()->AddRemoteCandidate(
CreateUdpCandidate(LOCAL_PORT_TYPE, "hostname.test", 1, 100));
CreateUdpCandidate(IceCandidateType::kHost, "hostname.test", 1, 100));
EXPECT_TRUE(lookup_started);

View File

@ -39,9 +39,12 @@
#include "rtc_base/time_utils.h"
#include "rtc_base/trace_event.h"
using webrtc::IceCandidateType;
namespace cricket {
namespace {
using ::webrtc::IceCandidateType;
using ::webrtc::RTCError;
using ::webrtc::RTCErrorType;
using ::webrtc::TaskQueueBase;
@ -86,6 +89,17 @@ absl::optional<ProtocolType> StringToProto(absl::string_view proto_name) {
return absl::nullopt;
}
IceCandidateType PortTypeToIceCandidateType(const absl::string_view type) {
if (type == "host" || type == LOCAL_PORT_TYPE)
return IceCandidateType::kHost;
if (type == "srflx" || type == STUN_PORT_TYPE)
return IceCandidateType::kSrflx;
if (type == PRFLX_PORT_TYPE)
return IceCandidateType::kPrflx;
RTC_DCHECK_EQ(type, RELAY_PORT_TYPE);
return IceCandidateType::kRelay;
}
// RFC 6544, TCP candidate encoding rules.
const int DISCARD_PORT = 9;
const char TCPTYPE_ACTIVE_STR[] = "active";
@ -93,45 +107,36 @@ const char TCPTYPE_PASSIVE_STR[] = "passive";
const char TCPTYPE_SIMOPEN_STR[] = "so";
Port::Port(TaskQueueBase* thread,
absl::string_view type,
webrtc::IceCandidateType type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
absl::string_view username_fragment,
absl::string_view password,
const webrtc::FieldTrialsView* field_trials)
: thread_(thread),
factory_(factory),
type_(type),
send_retransmit_count_attribute_(false),
network_(network),
min_port_(0),
max_port_(0),
component_(ICE_CANDIDATE_COMPONENT_DEFAULT),
generation_(0),
ice_username_fragment_(username_fragment),
password_(password),
timeout_delay_(kPortTimeoutDelay),
enable_port_packets_(false),
ice_role_(ICEROLE_UNKNOWN),
tiebreaker_(0),
shared_socket_(true),
weak_factory_(this),
field_trials_(field_trials) {
RTC_DCHECK(factory_ != NULL);
Construct();
}
: Port(thread,
type,
factory,
network,
0,
0,
username_fragment,
password,
field_trials,
true) {}
Port::Port(TaskQueueBase* thread,
absl::string_view type,
webrtc::IceCandidateType type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
absl::string_view username_fragment,
absl::string_view password,
const webrtc::FieldTrialsView* field_trials)
const webrtc::FieldTrialsView* field_trials,
bool shared_socket /*= false*/)
: thread_(thread),
factory_(factory),
field_trials_(field_trials),
type_(type),
send_retransmit_count_attribute_(false),
network_(network),
@ -145,15 +150,11 @@ Port::Port(TaskQueueBase* thread,
enable_port_packets_(false),
ice_role_(ICEROLE_UNKNOWN),
tiebreaker_(0),
shared_socket_(false),
weak_factory_(this),
field_trials_(field_trials) {
RTC_DCHECK(factory_ != NULL);
Construct();
}
void Port::Construct() {
shared_socket_(shared_socket),
network_cost_(network->GetCost(*field_trials_)),
weak_factory_(this) {
RTC_DCHECK_RUN_ON(thread_);
RTC_DCHECK(factory_ != nullptr);
// TODO(pthatcher): Remove this old behavior once we're sure no one
// relies on it. If the username_fragment and password are empty,
// we should just create one.
@ -163,7 +164,6 @@ void Port::Construct() {
password_ = rtc::CreateRandomString(ICE_PWD_LENGTH);
}
network_->SignalTypeChanged.connect(this, &Port::OnNetworkTypeChanged);
network_cost_ = network_->GetCost(field_trials());
PostDestroyIfDead(/*delayed=*/true);
RTC_LOG(LS_INFO) << ToString() << ": Port created with network cost "
@ -177,7 +177,11 @@ Port::~Port() {
}
const absl::string_view Port::Type() const {
return type_;
if (type_ == webrtc::IceCandidateType::kHost)
return "local";
if (type_ == webrtc::IceCandidateType::kSrflx)
return "stun";
return webrtc::IceCandidateTypeToString(type_);
}
const rtc::Network* Port::Network() const {
return network_;
@ -241,7 +245,7 @@ void Port::AddAddress(const rtc::SocketAddress& address,
absl::string_view protocol,
absl::string_view relay_protocol,
absl::string_view tcptype,
absl::string_view type,
IceCandidateType type,
uint32_t type_preference,
uint32_t relay_preference,
absl::string_view url,
@ -873,8 +877,9 @@ void Port::OnNetworkTypeChanged(const rtc::Network* network) {
std::string Port::ToString() const {
rtc::StringBuilder ss;
ss << "Port[" << rtc::ToHex(reinterpret_cast<uintptr_t>(this)) << ":"
<< content_name_ << ":" << component_ << ":" << generation_ << ":" << type_
<< ":" << network_->ToString() << "]";
<< content_name_ << ":" << component_ << ":" << generation_ << ":"
<< webrtc::IceCandidateTypeToString(type_) << ":" << network_->ToString()
<< "]";
return ss.Release();
}

View File

@ -123,6 +123,8 @@ typedef std::vector<CandidateStats> CandidateStatsList;
const char* ProtoToString(ProtocolType proto);
absl::optional<ProtocolType> StringToProto(absl::string_view proto_name);
webrtc::IceCandidateType PortTypeToIceCandidateType(
const absl::string_view type);
struct ProtocolAddress {
rtc::SocketAddress address;
@ -171,29 +173,67 @@ typedef std::set<rtc::SocketAddress> ServerAddresses;
// connections to similar mechanisms of the other client. Subclasses of this
// one add support for specific mechanisms like local UDP ports.
class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> {
public:
// INIT: The state when a port is just created.
// KEEP_ALIVE_UNTIL_PRUNED: A port should not be destroyed even if no
// connection is using it.
// PRUNED: It will be destroyed if no connection is using it for a period of
// 30 seconds.
enum class State { INIT, KEEP_ALIVE_UNTIL_PRUNED, PRUNED };
protected:
// Constructors for use only by via constructors in derived classes.
Port(webrtc::TaskQueueBase* thread,
absl::string_view type ABSL_ATTRIBUTE_LIFETIME_BOUND,
webrtc::IceCandidateType type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
absl::string_view username_fragment,
absl::string_view password,
const webrtc::FieldTrialsView* field_trials = nullptr);
Port(webrtc::TaskQueueBase* thread,
absl::string_view type ABSL_ATTRIBUTE_LIFETIME_BOUND,
webrtc::IceCandidateType type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
absl::string_view username_fragment,
absl::string_view password,
const webrtc::FieldTrialsView* field_trials = nullptr);
const webrtc::FieldTrialsView* field_trials = nullptr,
bool shared_socket = false);
// // TODO: bugs.webrtc.org/15846 - Remove.
[[deprecated("Use IceCandidateType version")]] Port(
webrtc::TaskQueueBase* thread,
absl::string_view type ABSL_ATTRIBUTE_LIFETIME_BOUND,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
absl::string_view username_fragment,
absl::string_view password,
const webrtc::FieldTrialsView* field_trials = nullptr,
bool shared_socket = false)
: Port(thread,
PortTypeToIceCandidateType(type),
factory,
network,
min_port,
max_port,
username_fragment,
password,
field_trials,
shared_socket) {}
// // TODO: bugs.webrtc.org/15846 - Remove.
[[deprecated("Use IceCandidateType version")]] Port(
webrtc::TaskQueueBase* thread,
absl::string_view type ABSL_ATTRIBUTE_LIFETIME_BOUND,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
absl::string_view username_fragment,
absl::string_view password,
const webrtc::FieldTrialsView* field_trials = nullptr)
: Port(thread,
PortTypeToIceCandidateType(type),
factory,
network,
username_fragment,
password,
field_trials) {}
public:
~Port() override;
// Note that the port type does NOT uniquely identify different subclasses of
@ -379,13 +419,31 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> {
rtc::WeakPtr<Port> NewWeakPtr() { return weak_factory_.GetWeakPtr(); }
// TODO: bugs.webrtc.org/15846 - Remove.
[[deprecated("Use IceCandidateType version")]] void AddAddress(
const rtc::SocketAddress& address,
const rtc::SocketAddress& base_address,
const rtc::SocketAddress& related_address,
absl::string_view protocol,
absl::string_view relay_protocol,
absl::string_view tcptype,
absl::string_view type,
uint32_t type_preference,
uint32_t relay_preference,
absl::string_view url,
bool is_final) {
AddAddress(address, base_address, related_address, protocol, relay_protocol,
tcptype, PortTypeToIceCandidateType(type), type_preference,
relay_preference, url, is_final);
}
void AddAddress(const rtc::SocketAddress& address,
const rtc::SocketAddress& base_address,
const rtc::SocketAddress& related_address,
absl::string_view protocol,
absl::string_view relay_protocol,
absl::string_view tcptype,
absl::string_view type,
webrtc::IceCandidateType type,
uint32_t type_preference,
uint32_t relay_preference,
absl::string_view url,
@ -451,8 +509,11 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> {
const webrtc::FieldTrialsView& field_trials() const { return *field_trials_; }
webrtc::IceCandidateType type() const { return type_; }
private:
void Construct();
bool MaybeObfuscateAddress(const Candidate& c, bool is_final)
RTC_RUN_ON(thread_);
void PostDestroyIfDead(bool delayed);
void DestroyIfDead();
@ -474,7 +535,10 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> {
webrtc::TaskQueueBase* const thread_;
rtc::PacketSocketFactory* const factory_;
const absl::string_view type_;
webrtc::AlwaysValidPointer<const webrtc::FieldTrialsView,
webrtc::FieldTrialBasedConfig>
field_trials_;
const webrtc::IceCandidateType type_;
bool send_retransmit_count_attribute_;
const rtc::Network* network_;
uint16_t min_port_;
@ -503,20 +567,21 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> {
// (WiFi. vs. Cellular). It takes precedence over the priority when
// comparing two connections.
int16_t network_cost_;
// INIT: The state when a port is just created.
// KEEP_ALIVE_UNTIL_PRUNED: A port should not be destroyed even if no
// connection is using it.
// PRUNED: It will be destroyed if no connection is using it for a period of
// 30 seconds.
enum class State { INIT, KEEP_ALIVE_UNTIL_PRUNED, PRUNED };
State state_ = State::INIT;
int64_t last_time_all_connections_removed_ = 0;
MdnsNameRegistrationStatus mdns_name_registration_status_ =
MdnsNameRegistrationStatus::kNotStarted;
rtc::WeakPtrFactory<Port> weak_factory_;
webrtc::AlwaysValidPointer<const webrtc::FieldTrialsView,
webrtc::FieldTrialBasedConfig>
field_trials_;
bool MaybeObfuscateAddress(const Candidate& c, bool is_final)
RTC_RUN_ON(thread_);
webrtc::CallbackList<PortInterface*> port_destroyed_callback_list_;
// Keep as the last member variable.
rtc::WeakPtrFactory<Port> weak_factory_;
};
} // namespace cricket

View File

@ -19,6 +19,8 @@
#include "test/gtest.h"
#include "test/scoped_key_value_config.h"
using webrtc::IceCandidateType;
static const char kContentName[] = "test content";
// Based on ICE_UFRAG_LENGTH
static const char kIceUfrag[] = "UF00";
@ -294,7 +296,7 @@ TEST_F(PortAllocatorTest, SanitizeEmptyCandidateDefaultConfig) {
TEST_F(PortAllocatorTest, SanitizeIpv4CandidateDefaultConfig) {
cricket::Candidate input(1, "udp", rtc::SocketAddress(kIpv4Address, 443), 1,
"username", "password", cricket::LOCAL_PORT_TYPE, 1,
"username", "password", IceCandidateType::kHost, 1,
"foundation", 1, 1);
cricket::Candidate output = allocator_->SanitizeCandidate(input);
EXPECT_EQ(kIpv4AddressWithPort, output.address().ToString());
@ -304,7 +306,7 @@ TEST_F(PortAllocatorTest, SanitizeIpv4CandidateDefaultConfig) {
TEST_F(PortAllocatorTest, SanitizeIpv4CandidateMdnsObfuscationEnabled) {
allocator_->SetMdnsObfuscationEnabledForTesting(true);
cricket::Candidate input(1, "udp", rtc::SocketAddress(kIpv4Address, 443), 1,
"username", "password", cricket::LOCAL_PORT_TYPE, 1,
"username", "password", IceCandidateType::kHost, 1,
"foundation", 1, 1);
cricket::Candidate output = allocator_->SanitizeCandidate(input);
EXPECT_NE(kIpv4AddressWithPort, output.address().ToString());
@ -315,7 +317,7 @@ TEST_F(PortAllocatorTest, SanitizePrflxCandidateMdnsObfuscationEnabled) {
allocator_->SetMdnsObfuscationEnabledForTesting(true);
// Create the candidate from an IP literal. This populates the hostname.
cricket::Candidate input(1, "udp", rtc::SocketAddress(kIpv4Address, 443), 1,
"username", "password", cricket::PRFLX_PORT_TYPE, 1,
"username", "password", IceCandidateType::kPrflx, 1,
"foundation", 1, 1);
cricket::Candidate output = allocator_->SanitizeCandidate(input);
EXPECT_NE(kIpv4AddressWithPort, output.address().ToString());
@ -327,7 +329,7 @@ TEST_F(PortAllocatorTest,
allocator_->SetMdnsObfuscationEnabledForTesting(true);
// Create the candidate from an IP literal. This populates the hostname.
cricket::Candidate input(1, "udp", rtc::SocketAddress(kIpv4Address, 443), 1,
"username", "password", cricket::PRFLX_PORT_TYPE, 1,
"username", "password", IceCandidateType::kPrflx, 1,
"foundation", 1, 1);
cricket::Candidate output = allocator_->SanitizeCandidate(input);
@ -343,8 +345,8 @@ TEST_F(PortAllocatorTest, SanitizeIpv4NonLiteralMdnsObfuscationEnabled) {
rtc::IPAddress ip;
EXPECT_TRUE(IPFromString(kIpv4Address, &ip));
cricket::Candidate input(1, "udp", rtc::SocketAddress(ip, 443), 1, "username",
"password", cricket::LOCAL_PORT_TYPE, 1,
"foundation", 1, 1);
"password", IceCandidateType::kHost, 1, "foundation",
1, 1);
cricket::Candidate output = allocator_->SanitizeCandidate(input);
EXPECT_NE(kIpv4AddressWithPort, output.address().ToString());
EXPECT_EQ("", output.address().ipaddr().ToString());

View File

@ -52,6 +52,7 @@ class PortInterface {
public:
virtual ~PortInterface();
// TODO: bugs.webrtc.org/15846 - Change return type to IceCandidateType.
virtual const absl::string_view Type() const = 0;
virtual const rtc::Network* Network() const = 0;

View File

@ -82,6 +82,7 @@ using rtc::NATType;
using rtc::PacketSocketFactory;
using rtc::Socket;
using rtc::SocketAddress;
using webrtc::IceCandidateType;
namespace cricket {
namespace {
@ -141,7 +142,6 @@ bool WriteStunMessage(const StunMessage& msg, ByteBufferWriter* buf) {
class TestPort : public Port {
public:
TestPort(rtc::Thread* thread,
absl::string_view type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
uint16_t min_port,
@ -150,7 +150,7 @@ class TestPort : public Port {
absl::string_view password,
const webrtc::FieldTrialsView* field_trials = nullptr)
: Port(thread,
type,
IceCandidateType::kHost,
factory,
network,
min_port,
@ -185,7 +185,7 @@ class TestPort : public Port {
// Act as if the socket was bound to the best IP on the network, to the
// first port in the allowed range.
rtc::SocketAddress addr(Network()->GetBestIP(), min_port());
AddAddress(addr, addr, rtc::SocketAddress(), "udp", "", "", Type(),
AddAddress(addr, addr, rtc::SocketAddress(), "udp", "", "", type(),
ICE_TYPE_PREFERENCE_HOST, 0, "", true);
}
@ -197,12 +197,12 @@ class TestPort : public Port {
// Exposed for testing candidate building.
void AddCandidateAddress(const rtc::SocketAddress& addr) {
AddAddress(addr, addr, rtc::SocketAddress(), "udp", "", "", Type(),
AddAddress(addr, addr, rtc::SocketAddress(), "udp", "", "", type(),
type_preference_, 0, "", false);
}
void AddCandidateAddress(const rtc::SocketAddress& addr,
const rtc::SocketAddress& base_address,
absl::string_view type,
IceCandidateType type,
int type_preference,
bool final) {
AddAddress(addr, base_address, rtc::SocketAddress(), "udp", "", "", type,
@ -825,9 +825,9 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> {
absl::string_view username,
absl::string_view password,
const webrtc::FieldTrialsView* field_trials = nullptr) {
auto port = std::make_unique<TestPort>(
&main_, cricket::LOCAL_PORT_TYPE, &socket_factory_, MakeNetwork(addr),
0, 0, username, password, field_trials);
auto port =
std::make_unique<TestPort>(&main_, &socket_factory_, MakeNetwork(addr),
0, 0, username, password, field_trials);
port->SignalRoleConflict.connect(this, &PortTest::OnRoleConflict);
return port;
}
@ -845,9 +845,8 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> {
std::unique_ptr<TestPort> CreateTestPort(const rtc::Network* network,
absl::string_view username,
absl::string_view password) {
auto port = std::make_unique<TestPort>(&main_, cricket::LOCAL_PORT_TYPE,
&socket_factory_, network, 0, 0,
username, password);
auto port = std::make_unique<TestPort>(&main_, &socket_factory_, network, 0,
0, username, password);
port->SignalRoleConflict.connect(this, &PortTest::OnRoleConflict);
return port;
}
@ -2704,9 +2703,11 @@ TEST_F(PortTest, TestComputeCandidatePriorityWithPriorityAdjustment) {
TEST_F(PortTest, TestFoundation) {
auto testport = CreateTestPort(kLocalAddr1, "name", "pass");
testport->SetIceTiebreaker(kTiebreakerDefault);
testport->AddCandidateAddress(kLocalAddr1, kLocalAddr1, LOCAL_PORT_TYPE,
testport->AddCandidateAddress(kLocalAddr1, kLocalAddr1,
IceCandidateType::kHost,
cricket::ICE_TYPE_PREFERENCE_HOST, false);
testport->AddCandidateAddress(kLocalAddr2, kLocalAddr1, STUN_PORT_TYPE,
testport->AddCandidateAddress(kLocalAddr2, kLocalAddr1,
IceCandidateType::kSrflx,
cricket::ICE_TYPE_PREFERENCE_SRFLX, true);
EXPECT_NE(testport->Candidates()[0].foundation(),
testport->Candidates()[1].foundation());
@ -3775,7 +3776,8 @@ TEST_F(PortTest, TestAddConnectionWithSameAddress) {
port->PrepareAddress();
EXPECT_EQ(1u, port->Candidates().size());
rtc::SocketAddress address("1.1.1.1", 5000);
cricket::Candidate candidate(1, "udp", address, 0, "", "", "relay", 0, "");
cricket::Candidate candidate(1, "udp", address, 0, "", "",
IceCandidateType::kRelay, 0, "");
cricket::Connection* conn1 =
port->CreateConnection(candidate, Port::ORIGIN_MESSAGE);
cricket::Connection* conn_in_use = port->GetConnection(address);

View File

@ -160,7 +160,7 @@ bool UDPPort::AddressResolver::GetResolvedAddress(
}
UDPPort::UDPPort(rtc::Thread* thread,
absl::string_view type,
webrtc::IceCandidateType type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
rtc::AsyncPacketSocket* socket,
@ -182,7 +182,7 @@ UDPPort::UDPPort(rtc::Thread* thread,
emit_local_for_anyaddress_(emit_local_for_anyaddress) {}
UDPPort::UDPPort(rtc::Thread* thread,
absl::string_view type,
webrtc::IceCandidateType type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
uint16_t min_port,
@ -380,7 +380,8 @@ void UDPPort::OnLocalAddressReady(rtc::AsyncPacketSocket* socket,
MaybeSetDefaultLocalAddress(&addr);
AddAddress(addr, addr, rtc::SocketAddress(), UDP_PROTOCOL_NAME, "", "",
LOCAL_PORT_TYPE, ICE_TYPE_PREFERENCE_HOST, 0, "", false);
webrtc::IceCandidateType::kHost, ICE_TYPE_PREFERENCE_HOST, 0, "",
false);
MaybePrepareStunCandidate();
}
@ -541,7 +542,7 @@ void UDPPort::OnStunBindingRequestSucceeded(
url << "stun:" << stun_server_addr.hostname() << ":"
<< stun_server_addr.port();
AddAddress(stun_reflected_addr, socket_->GetLocalAddress(), related_address,
UDP_PROTOCOL_NAME, "", "", STUN_PORT_TYPE,
UDP_PROTOCOL_NAME, "", "", webrtc::IceCandidateType::kSrflx,
ICE_TYPE_PREFERENCE_SRFLX, 0, url.str(), false);
}
MaybeSetPortCompleteOrError();
@ -654,7 +655,7 @@ StunPort::StunPort(rtc::Thread* thread,
const ServerAddresses& servers,
const webrtc::FieldTrialsView* field_trials)
: UDPPort(thread,
STUN_PORT_TYPE,
webrtc::IceCandidateType::kSrflx,
factory,
network,
min_port,

View File

@ -46,9 +46,9 @@ class RTC_EXPORT UDPPort : public Port {
absl::optional<int> stun_keepalive_interval,
const webrtc::FieldTrialsView* field_trials = nullptr) {
// Using `new` to access a non-public constructor.
auto port = absl::WrapUnique(
new UDPPort(thread, LOCAL_PORT_TYPE, factory, network, socket, username,
password, emit_local_for_anyaddress, field_trials));
auto port = absl::WrapUnique(new UDPPort(
thread, webrtc::IceCandidateType::kHost, factory, network, socket,
username, password, emit_local_for_anyaddress, field_trials));
port->set_stun_keepalive_delay(stun_keepalive_interval);
if (!port->Init()) {
return nullptr;
@ -69,8 +69,8 @@ class RTC_EXPORT UDPPort : public Port {
const webrtc::FieldTrialsView* field_trials = nullptr) {
// Using `new` to access a non-public constructor.
auto port = absl::WrapUnique(new UDPPort(
thread, LOCAL_PORT_TYPE, factory, network, min_port, max_port, username,
password, emit_local_for_anyaddress, field_trials));
thread, webrtc::IceCandidateType::kHost, factory, network, min_port,
max_port, username, password, emit_local_for_anyaddress, field_trials));
port->set_stun_keepalive_delay(stun_keepalive_interval);
if (!port->Init()) {
return nullptr;
@ -118,7 +118,7 @@ class RTC_EXPORT UDPPort : public Port {
protected:
UDPPort(rtc::Thread* thread,
absl::string_view type,
webrtc::IceCandidateType type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
uint16_t min_port,
@ -129,7 +129,7 @@ class RTC_EXPORT UDPPort : public Port {
const webrtc::FieldTrialsView* field_trials);
UDPPort(rtc::Thread* thread,
absl::string_view type,
webrtc::IceCandidateType type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
rtc::AsyncPacketSocket* socket,

View File

@ -86,6 +86,7 @@
#include "rtc_base/thread.h"
namespace cricket {
using ::webrtc::IceCandidateType;
using ::webrtc::SafeTask;
using ::webrtc::TimeDelta;
@ -99,7 +100,7 @@ TCPPort::TCPPort(rtc::Thread* thread,
bool allow_listen,
const webrtc::FieldTrialsView* field_trials)
: Port(thread,
LOCAL_PORT_TYPE,
IceCandidateType::kHost,
factory,
network,
min_port,
@ -181,10 +182,10 @@ void TCPPort::PrepareAddress() {
// failed, we still want to add the socket address.
RTC_LOG(LS_VERBOSE) << "Preparing TCP address, current state: "
<< static_cast<int>(listen_socket_->GetState());
AddAddress(listen_socket_->GetLocalAddress(),
listen_socket_->GetLocalAddress(), rtc::SocketAddress(),
TCP_PROTOCOL_NAME, "", TCPTYPE_PASSIVE_STR, LOCAL_PORT_TYPE,
ICE_TYPE_PREFERENCE_HOST_TCP, 0, "", true);
AddAddress(
listen_socket_->GetLocalAddress(), listen_socket_->GetLocalAddress(),
rtc::SocketAddress(), TCP_PROTOCOL_NAME, "", TCPTYPE_PASSIVE_STR,
IceCandidateType::kHost, ICE_TYPE_PREFERENCE_HOST_TCP, 0, "", true);
} else {
RTC_LOG(LS_INFO) << ToString()
<< ": Not listening due to firewall restrictions.";
@ -199,7 +200,8 @@ void TCPPort::PrepareAddress() {
AddAddress(rtc::SocketAddress(Network()->GetBestIP(), DISCARD_PORT),
rtc::SocketAddress(Network()->GetBestIP(), 0),
rtc::SocketAddress(), TCP_PROTOCOL_NAME, "", TCPTYPE_ACTIVE_STR,
LOCAL_PORT_TYPE, ICE_TYPE_PREFERENCE_HOST_TCP, 0, "", true);
IceCandidateType::kHost, ICE_TYPE_PREFERENCE_HOST_TCP, 0, "",
true);
}
}

View File

@ -37,6 +37,7 @@
namespace cricket {
using ::webrtc::IceCandidateType;
using ::webrtc::SafeTask;
using ::webrtc::TaskQueueBase;
using ::webrtc::TimeDelta;
@ -222,7 +223,7 @@ TurnPort::TurnPort(TaskQueueBase* thread,
rtc::SSLCertificateVerifier* tls_cert_verifier,
const webrtc::FieldTrialsView* field_trials)
: Port(thread,
RELAY_PORT_TYPE,
IceCandidateType::kRelay,
factory,
network,
username,
@ -264,7 +265,7 @@ TurnPort::TurnPort(TaskQueueBase* thread,
rtc::SSLCertificateVerifier* tls_cert_verifier,
const webrtc::FieldTrialsView* field_trials)
: Port(thread,
RELAY_PORT_TYPE,
IceCandidateType::kRelay,
factory,
network,
min_port,
@ -887,8 +888,9 @@ void TurnPort::OnAllocateSuccess(const rtc::SocketAddress& address,
UDP_PROTOCOL_NAME,
ProtoToString(server_address_.proto), // The first hop protocol.
"", // TCP candidate type, empty for turn candidates.
RELAY_PORT_TYPE, GetRelayPreference(server_address_.proto),
server_priority_, server_url_, true);
IceCandidateType::kRelay,
GetRelayPreference(server_address_.proto), server_priority_,
server_url_, true);
}
void TurnPort::OnAllocateError(int error_code, absl::string_view reason) {

View File

@ -57,6 +57,7 @@ using ::testing::DoAll;
using ::testing::Return;
using ::testing::ReturnPointee;
using ::testing::SetArgPointee;
using ::webrtc::IceCandidateType;
static const SocketAddress kLocalAddr1("11.11.11.11", 0);
static const SocketAddress kLocalAddr2("22.22.22.22", 0);
@ -1598,7 +1599,8 @@ TEST_F(TurnPortTest, TestCandidateAddressFamilyMatch) {
// Create an IPv4 candidate. It will match the TURN candidate.
Candidate remote_candidate(ICE_CANDIDATE_COMPONENT_RTP, "udp", kLocalAddr2, 0,
"", "", "local", 0, kCandidateFoundation);
"", "", IceCandidateType::kHost, 0,
kCandidateFoundation);
remote_candidate.set_address(kLocalAddr2);
Connection* conn =
turn_port_->CreateConnection(remote_candidate, Port::ORIGIN_MESSAGE);

View File

@ -36,6 +36,7 @@ using cricket::MediaProtocolType;
using ::testing::Values;
using webrtc::IceCandidateCollection;
using webrtc::IceCandidateInterface;
using webrtc::IceCandidateType;
using webrtc::JsepIceCandidate;
using webrtc::JsepSessionDescription;
using webrtc::SdpType;
@ -89,7 +90,8 @@ class JsepSessionDescriptionTest : public ::testing::Test {
int port = 1234;
rtc::SocketAddress address("127.0.0.1", port++);
cricket::Candidate candidate(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
address, 1, "", "", "local", 0, "1");
address, 1, "", "", IceCandidateType::kHost, 0,
"1");
candidate_ = candidate;
const std::string session_id = rtc::ToString(rtc::CreateRandomId64());
const std::string session_version = rtc::ToString(rtc::CreateRandomId());
@ -138,11 +140,11 @@ TEST_F(JsepSessionDescriptionTest, CloneWithCandidates) {
cricket::Candidate candidate_v4(
cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
IceCandidateType::kSrflx, kCandidateGeneration, kCandidateFoundation);
cricket::Candidate candidate_v6(
cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
IceCandidateType::kHost, kCandidateGeneration, kCandidateFoundation);
JsepIceCandidate jice_v4("audio", 0, candidate_v4);
JsepIceCandidate jice_v6("audio", 0, candidate_v6);
@ -265,7 +267,7 @@ TEST_F(JsepSessionDescriptionTest, AddHostnameCandidate) {
c.set_component(cricket::ICE_CANDIDATE_COMPONENT_RTP);
c.set_protocol(cricket::UDP_PROTOCOL_NAME);
c.set_address(rtc::SocketAddress("example.local", 1234));
c.set_type(cricket::LOCAL_PORT_TYPE);
c.set_type(IceCandidateType::kHost);
const size_t audio_index = 0;
JsepIceCandidate hostname_candidate("audio", audio_index, c);
EXPECT_TRUE(jsep_desc_->AddCandidate(&hostname_candidate));
@ -296,7 +298,7 @@ TEST_F(JsepSessionDescriptionTest, SerializeDeserializeWithHostnameCandidate) {
c.set_component(cricket::ICE_CANDIDATE_COMPONENT_RTP);
c.set_protocol(cricket::UDP_PROTOCOL_NAME);
c.set_address(rtc::SocketAddress("example.local", 1234));
c.set_type(cricket::LOCAL_PORT_TYPE);
c.set_type(IceCandidateType::kHost);
const size_t audio_index = 0;
const size_t video_index = 1;
JsepIceCandidate hostname_candidate_audio("audio", audio_index, c);
@ -348,11 +350,11 @@ TEST_F(JsepSessionDescriptionTest, SerializeSessionDescriptionWithIPv6Only) {
cricket::Candidate candidate1(
cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
IceCandidateType::kSrflx, kCandidateGeneration, kCandidateFoundation);
cricket::Candidate candidate2(
cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
IceCandidateType::kHost, kCandidateGeneration, kCandidateFoundation);
JsepIceCandidate jice1("audio", 0, candidate1);
JsepIceCandidate jice2("audio", 0, candidate2);
@ -378,11 +380,11 @@ TEST_F(JsepSessionDescriptionTest,
cricket::Candidate candidate_v4(
cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
IceCandidateType::kSrflx, kCandidateGeneration, kCandidateFoundation);
cricket::Candidate candidate_v6(
cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
IceCandidateType::kHost, kCandidateGeneration, kCandidateFoundation);
JsepIceCandidate jice_v4("audio", 0, candidate_v4);
JsepIceCandidate jice_v6("audio", 0, candidate_v6);
@ -409,11 +411,11 @@ TEST_F(JsepSessionDescriptionTest,
cricket::Candidate candidate1(
cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
IceCandidateType::kSrflx, kCandidateGeneration, kCandidateFoundation);
cricket::Candidate candidate2(
cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
"", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
"", "", IceCandidateType::kHost, kCandidateGeneration,
kCandidateFoundation);
JsepIceCandidate jice1("audio", 0, candidate1);
@ -440,11 +442,11 @@ TEST_F(JsepSessionDescriptionTest, SerializeSessionDescriptionWithTCPOnly) {
cricket::Candidate candidate1(
cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
IceCandidateType::kSrflx, kCandidateGeneration, kCandidateFoundation);
cricket::Candidate candidate2(
cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
IceCandidateType::kHost, kCandidateGeneration, kCandidateFoundation);
JsepIceCandidate jice1("audio", 0, candidate1);
JsepIceCandidate jice2("audio", 0, candidate2);
@ -467,19 +469,19 @@ TEST_F(JsepSessionDescriptionTest, RemoveCandidateAndSetConnectionAddress) {
cricket::Candidate candidate1(
cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
IceCandidateType::kHost, kCandidateGeneration, kCandidateFoundation);
candidate1.set_transport_name("audio");
cricket::Candidate candidate2(
cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
IceCandidateType::kHost, kCandidateGeneration, kCandidateFoundation);
candidate2.set_transport_name("audio");
cricket::Candidate candidate3(
cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
rtc::SocketAddress("192.168.1.1", 1236), kCandidatePriority, "", "",
cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
IceCandidateType::kHost, kCandidateGeneration, kCandidateFoundation);
candidate3.set_transport_name("audio");
JsepIceCandidate jice1("audio", 0, candidate1);

View File

@ -1342,7 +1342,7 @@ TEST_F(LegacyStatsCollectorTest, IceCandidateReport) {
cricket::Candidate local;
EXPECT_GT(local.id().length(), 0u);
local.set_type(cricket::LOCAL_PORT_TYPE);
RTC_DCHECK_EQ(local.type(), IceCandidateType::kHost);
local.set_protocol(cricket::UDP_PROTOCOL_NAME);
local.set_address(kLocalAddress);
local.set_priority(kPriority);
@ -1350,7 +1350,7 @@ TEST_F(LegacyStatsCollectorTest, IceCandidateReport) {
cricket::Candidate remote;
EXPECT_GT(remote.id().length(), 0u);
remote.set_type(cricket::PRFLX_PORT_TYPE);
remote.set_type(IceCandidateType::kPrflx);
remote.set_protocol(cricket::UDP_PROTOCOL_NAME);
remote.set_address(kRemoteAddress);
remote.set_priority(kPriority);

View File

@ -278,7 +278,6 @@ class PeerConnectionBundleBaseTest : public ::testing::Test {
candidate.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT);
candidate.set_protocol(cricket::UDP_PROTOCOL_NAME);
candidate.set_address(address);
candidate.set_type(cricket::LOCAL_PORT_TYPE);
return candidate;
}

View File

@ -214,10 +214,10 @@ class PeerConnectionIceBaseTest : public ::testing::Test {
cricket::Candidate CreateLocalUdpCandidate(
const rtc::SocketAddress& address) {
cricket::Candidate candidate;
RTC_DCHECK_EQ(candidate.type(), IceCandidateType::kHost);
candidate.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT);
candidate.set_protocol(cricket::UDP_PROTOCOL_NAME);
candidate.set_address(address);
candidate.set_type(cricket::LOCAL_PORT_TYPE);
return candidate;
}

View File

@ -212,7 +212,7 @@ std::unique_ptr<cricket::Candidate> CreateFakeCandidate(
int port,
const std::string& protocol,
const rtc::AdapterType adapter_type,
const absl::string_view candidate_type,
IceCandidateType candidate_type,
uint32_t priority,
const rtc::AdapterType underlying_type_for_vpn =
rtc::ADAPTER_TYPE_UNKNOWN) {
@ -1660,7 +1660,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) {
// Candidates in the first transport stats.
std::unique_ptr<cricket::Candidate> a_local_host = CreateFakeCandidate(
"1.2.3.4", 5, "a_local_host's protocol", rtc::ADAPTER_TYPE_VPN,
cricket::LOCAL_PORT_TYPE, 0, rtc::ADAPTER_TYPE_ETHERNET);
IceCandidateType::kHost, 0, rtc::ADAPTER_TYPE_ETHERNET);
RTCLocalIceCandidateStats expected_a_local_host("I" + a_local_host->id(),
Timestamp::Zero());
expected_a_local_host.transport_id = "Ta0";
@ -1678,7 +1678,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) {
std::unique_ptr<cricket::Candidate> a_remote_srflx = CreateFakeCandidate(
"6.7.8.9", 10, "remote_srflx's protocol", rtc::ADAPTER_TYPE_UNKNOWN,
cricket::STUN_PORT_TYPE, 1);
IceCandidateType::kSrflx, 1);
RTCRemoteIceCandidateStats expected_a_remote_srflx("I" + a_remote_srflx->id(),
Timestamp::Zero());
expected_a_remote_srflx.transport_id = "Ta0";
@ -1693,7 +1693,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) {
std::unique_ptr<cricket::Candidate> a_local_prflx = CreateFakeCandidate(
"11.12.13.14", 15, "a_local_prflx's protocol",
rtc::ADAPTER_TYPE_CELLULAR_2G, cricket::PRFLX_PORT_TYPE, 2);
rtc::ADAPTER_TYPE_CELLULAR_2G, IceCandidateType::kPrflx, 2);
RTCLocalIceCandidateStats expected_a_local_prflx("I" + a_local_prflx->id(),
Timestamp::Zero());
expected_a_local_prflx.transport_id = "Ta0";
@ -1711,7 +1711,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) {
std::unique_ptr<cricket::Candidate> a_remote_relay = CreateFakeCandidate(
"16.17.18.19", 20, "a_remote_relay's protocol", rtc::ADAPTER_TYPE_UNKNOWN,
cricket::RELAY_PORT_TYPE, 3);
IceCandidateType::kRelay, 3);
RTCRemoteIceCandidateStats expected_a_remote_relay("I" + a_remote_relay->id(),
Timestamp::Zero());
expected_a_remote_relay.transport_id = "Ta0";
@ -1726,7 +1726,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) {
std::unique_ptr<cricket::Candidate> a_local_relay = CreateFakeCandidate(
"16.17.18.19", 21, "a_local_relay's protocol", rtc::ADAPTER_TYPE_UNKNOWN,
cricket::RELAY_PORT_TYPE, 1);
IceCandidateType::kRelay, 1);
a_local_relay->set_relay_protocol("tcp");
a_local_relay->set_url("turn:url1");
@ -1749,7 +1749,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) {
std::unique_ptr<cricket::Candidate> a_local_relay_prflx = CreateFakeCandidate(
"11.12.13.20", 22, "a_local_relay_prflx's protocol",
rtc::ADAPTER_TYPE_UNKNOWN, cricket::PRFLX_PORT_TYPE, 1);
rtc::ADAPTER_TYPE_UNKNOWN, IceCandidateType::kPrflx, 1);
a_local_relay_prflx->set_relay_protocol("udp");
RTCLocalIceCandidateStats expected_a_local_relay_prflx(
@ -1771,7 +1771,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) {
// A non-paired local candidate.
std::unique_ptr<cricket::Candidate> a_local_host_not_paired =
CreateFakeCandidate("1.2.3.4", 4404, "a_local_host_not_paired's protocol",
rtc::ADAPTER_TYPE_VPN, cricket::LOCAL_PORT_TYPE, 0,
rtc::ADAPTER_TYPE_VPN, IceCandidateType::kHost, 0,
rtc::ADAPTER_TYPE_ETHERNET);
RTCLocalIceCandidateStats expected_a_local_host_not_paired(
"I" + a_local_host_not_paired->id(), Timestamp::Zero());
@ -1792,7 +1792,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) {
// Candidates in the second transport stats.
std::unique_ptr<cricket::Candidate> b_local =
CreateFakeCandidate("42.42.42.42", 42, "b_local's protocol",
rtc::ADAPTER_TYPE_WIFI, cricket::LOCAL_PORT_TYPE, 42);
rtc::ADAPTER_TYPE_WIFI, IceCandidateType::kHost, 42);
RTCLocalIceCandidateStats expected_b_local("I" + b_local->id(),
Timestamp::Zero());
expected_b_local.transport_id = "Tb0";
@ -1810,7 +1810,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) {
std::unique_ptr<cricket::Candidate> b_remote = CreateFakeCandidate(
"42.42.42.42", 42, "b_remote's protocol", rtc::ADAPTER_TYPE_UNKNOWN,
cricket::LOCAL_PORT_TYPE, 42);
IceCandidateType::kHost, 42);
RTCRemoteIceCandidateStats expected_b_remote("I" + b_remote->id(),
Timestamp::Zero());
expected_b_remote.transport_id = "Tb0";
@ -1911,12 +1911,12 @@ TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) {
std::unique_ptr<cricket::Candidate> local_candidate =
CreateFakeCandidate("42.42.42.42", 42, "protocol", rtc::ADAPTER_TYPE_WIFI,
cricket::LOCAL_PORT_TYPE, 42);
IceCandidateType::kHost, 42);
local_candidate->set_username("local_iceusernamefragment");
std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate(
"42.42.42.42", 42, "protocol", rtc::ADAPTER_TYPE_UNKNOWN,
cricket::STUN_PORT_TYPE, 42);
IceCandidateType::kSrflx, 42);
remote_candidate->set_related_address(rtc::SocketAddress("192.168.2.1", 43));
remote_candidate->set_username("remote_iceusernamefragment");
@ -2735,17 +2735,17 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) {
std::unique_ptr<cricket::Candidate> rtp_local_candidate =
CreateFakeCandidate("42.42.42.42", 42, "protocol", rtc::ADAPTER_TYPE_WIFI,
cricket::LOCAL_PORT_TYPE, 42);
IceCandidateType::kHost, 42);
std::unique_ptr<cricket::Candidate> rtp_remote_candidate =
CreateFakeCandidate("42.42.42.42", 42, "protocol",
rtc::ADAPTER_TYPE_UNKNOWN, cricket::LOCAL_PORT_TYPE,
rtc::ADAPTER_TYPE_UNKNOWN, IceCandidateType::kHost,
42);
std::unique_ptr<cricket::Candidate> rtcp_local_candidate =
CreateFakeCandidate("42.42.42.42", 42, "protocol", rtc::ADAPTER_TYPE_WIFI,
cricket::LOCAL_PORT_TYPE, 42);
IceCandidateType::kHost, 42);
std::unique_ptr<cricket::Candidate> rtcp_remote_candidate =
CreateFakeCandidate("42.42.42.42", 42, "protocol",
rtc::ADAPTER_TYPE_UNKNOWN, cricket::LOCAL_PORT_TYPE,
rtc::ADAPTER_TYPE_UNKNOWN, IceCandidateType::kHost,
42);
cricket::ConnectionInfo rtp_connection_info;
@ -2907,17 +2907,17 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStatsWithCrypto) {
std::unique_ptr<cricket::Candidate> rtp_local_candidate =
CreateFakeCandidate("42.42.42.42", 42, "protocol", rtc::ADAPTER_TYPE_WIFI,
cricket::LOCAL_PORT_TYPE, 42);
IceCandidateType::kHost, 42);
std::unique_ptr<cricket::Candidate> rtp_remote_candidate =
CreateFakeCandidate("42.42.42.42", 42, "protocol",
rtc::ADAPTER_TYPE_UNKNOWN, cricket::LOCAL_PORT_TYPE,
rtc::ADAPTER_TYPE_UNKNOWN, IceCandidateType::kHost,
42);
std::unique_ptr<cricket::Candidate> rtcp_local_candidate =
CreateFakeCandidate("42.42.42.42", 42, "protocol", rtc::ADAPTER_TYPE_WIFI,
cricket::LOCAL_PORT_TYPE, 42);
IceCandidateType::kHost, 42);
std::unique_ptr<cricket::Candidate> rtcp_remote_candidate =
CreateFakeCandidate("42.42.42.42", 42, "protocol",
rtc::ADAPTER_TYPE_UNKNOWN, cricket::LOCAL_PORT_TYPE,
rtc::ADAPTER_TYPE_UNKNOWN, IceCandidateType::kHost,
42);
cricket::ConnectionInfo rtp_connection_info;

View File

@ -1120,16 +1120,16 @@ bool ParseCandidate(absl::string_view message,
return ParseFailed(first_line, "Unsupported transport type.", error);
}
absl::string_view candidate_type;
IceCandidateType candidate_type;
const absl::string_view type = fields[7];
if (type == kCandidateHost) {
candidate_type = cricket::LOCAL_PORT_TYPE;
candidate_type = IceCandidateType::kHost;
} else if (type == kCandidateSrflx) {
candidate_type = cricket::STUN_PORT_TYPE;
candidate_type = IceCandidateType::kSrflx;
} else if (type == kCandidateRelay) {
candidate_type = cricket::RELAY_PORT_TYPE;
candidate_type = IceCandidateType::kRelay;
} else if (type == kCandidatePrflx) {
candidate_type = cricket::PRFLX_PORT_TYPE;
candidate_type = IceCandidateType::kPrflx;
} else {
return ParseFailed(first_line, "Unsupported candidate type.", error);
}

View File

@ -61,9 +61,7 @@ using cricket::ContentInfo;
using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
using cricket::ICE_CANDIDATE_COMPONENT_RTP;
using cricket::kFecSsrcGroupSemantics;
using cricket::LOCAL_PORT_TYPE;
using cricket::MediaProtocolType;
using cricket::RELAY_PORT_TYPE;
using cricket::RidDescription;
using cricket::RidDirection;
using cricket::SctpDataContentDescription;
@ -71,7 +69,6 @@ using cricket::SessionDescription;
using cricket::SimulcastDescription;
using cricket::SimulcastLayer;
using cricket::StreamParams;
using cricket::STUN_PORT_TYPE;
using cricket::TransportDescription;
using cricket::TransportInfo;
using cricket::VideoContentDescription;
@ -79,6 +76,7 @@ using ::testing::ElementsAre;
using ::testing::Field;
using webrtc::IceCandidateCollection;
using webrtc::IceCandidateInterface;
using webrtc::IceCandidateType;
using webrtc::JsepIceCandidate;
using webrtc::JsepSessionDescription;
using webrtc::RtpExtension;
@ -1004,42 +1002,42 @@ class WebRtcSdpTest : public ::testing::Test {
int port = 1234;
rtc::SocketAddress address("192.168.1.5", port++);
Candidate candidate1(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
kCandidatePriority, "", "", LOCAL_PORT_TYPE,
kCandidatePriority, "", "", IceCandidateType::kHost,
kCandidateGeneration, kCandidateFoundation1);
address.SetPort(port++);
Candidate candidate2(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
kCandidatePriority, "", "", LOCAL_PORT_TYPE,
kCandidatePriority, "", "", IceCandidateType::kHost,
kCandidateGeneration, kCandidateFoundation1);
address.SetPort(port++);
Candidate candidate3(ICE_CANDIDATE_COMPONENT_RTCP, "udp", address,
kCandidatePriority, "", "", LOCAL_PORT_TYPE,
kCandidatePriority, "", "", IceCandidateType::kHost,
kCandidateGeneration, kCandidateFoundation1);
address.SetPort(port++);
Candidate candidate4(ICE_CANDIDATE_COMPONENT_RTP, "udp", address,
kCandidatePriority, "", "", LOCAL_PORT_TYPE,
kCandidatePriority, "", "", IceCandidateType::kHost,
kCandidateGeneration, kCandidateFoundation1);
// v6 host
rtc::SocketAddress v6_address("::1", port++);
cricket::Candidate candidate5(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
v6_address, kCandidatePriority, "", "",
cricket::LOCAL_PORT_TYPE,
kCandidateGeneration, kCandidateFoundation2);
IceCandidateType::kHost, kCandidateGeneration,
kCandidateFoundation2);
v6_address.SetPort(port++);
cricket::Candidate candidate6(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
v6_address, kCandidatePriority, "", "",
cricket::LOCAL_PORT_TYPE,
kCandidateGeneration, kCandidateFoundation2);
IceCandidateType::kHost, kCandidateGeneration,
kCandidateFoundation2);
v6_address.SetPort(port++);
cricket::Candidate candidate7(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
v6_address, kCandidatePriority, "", "",
cricket::LOCAL_PORT_TYPE,
kCandidateGeneration, kCandidateFoundation2);
IceCandidateType::kHost, kCandidateGeneration,
kCandidateFoundation2);
v6_address.SetPort(port++);
cricket::Candidate candidate8(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
v6_address, kCandidatePriority, "", "",
cricket::LOCAL_PORT_TYPE,
kCandidateGeneration, kCandidateFoundation2);
IceCandidateType::kHost, kCandidateGeneration,
kCandidateFoundation2);
// stun
int port_stun = 2345;
@ -1047,16 +1045,16 @@ class WebRtcSdpTest : public ::testing::Test {
rtc::SocketAddress rel_address_stun("192.168.1.5", port_stun++);
cricket::Candidate candidate9(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
address_stun, kCandidatePriority, "", "",
STUN_PORT_TYPE, kCandidateGeneration,
kCandidateFoundation3);
IceCandidateType::kSrflx,
kCandidateGeneration, kCandidateFoundation3);
candidate9.set_related_address(rel_address_stun);
address_stun.SetPort(port_stun++);
rel_address_stun.SetPort(port_stun++);
cricket::Candidate candidate10(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
address_stun, kCandidatePriority, "", "",
STUN_PORT_TYPE, kCandidateGeneration,
kCandidateFoundation3);
IceCandidateType::kSrflx,
kCandidateGeneration, kCandidateFoundation3);
candidate10.set_related_address(rel_address_stun);
// relay
@ -1064,13 +1062,13 @@ class WebRtcSdpTest : public ::testing::Test {
rtc::SocketAddress address_relay("74.125.224.39", port_relay++);
cricket::Candidate candidate11(cricket::ICE_CANDIDATE_COMPONENT_RTCP, "udp",
address_relay, kCandidatePriority, "", "",
cricket::RELAY_PORT_TYPE,
IceCandidateType::kRelay,
kCandidateGeneration, kCandidateFoundation4);
address_relay.SetPort(port_relay++);
cricket::Candidate candidate12(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
address_relay, kCandidatePriority, "", "",
RELAY_PORT_TYPE, kCandidateGeneration,
kCandidateFoundation4);
IceCandidateType::kRelay,
kCandidateGeneration, kCandidateFoundation4);
// voice
candidates_.push_back(candidate1);
@ -2233,9 +2231,10 @@ TEST_F(WebRtcSdpTest, SerializeCandidates) {
TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
rtc::SocketAddress address("a.test", 1234);
cricket::Candidate candidate(
cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", address, kCandidatePriority,
"", "", LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation1);
cricket::Candidate candidate(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
address, kCandidatePriority, "", "",
IceCandidateType::kHost, kCandidateGeneration,
kCandidateFoundation1);
JsepIceCandidate jcandidate(std::string("audio_content_name"), 0, candidate);
std::string message = webrtc::SdpSerializeCandidate(jcandidate);
EXPECT_EQ(std::string(kRawHostnameCandidate), message);
@ -2244,7 +2243,7 @@ TEST_F(WebRtcSdpTest, SerializeHostnameCandidate) {
TEST_F(WebRtcSdpTest, SerializeTcpCandidates) {
Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
"", "", LOCAL_PORT_TYPE, kCandidateGeneration,
"", "", IceCandidateType::kHost, kCandidateGeneration,
kCandidateFoundation1);
candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR);
std::unique_ptr<IceCandidateInterface> jcandidate(
@ -2648,7 +2647,7 @@ TEST_F(WebRtcSdpTest, DeserializeCandidate) {
// Make a cricket::Candidate equivalent to kSdpTcpCandidate string.
Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp",
rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority,
"", "", LOCAL_PORT_TYPE, kCandidateGeneration,
"", "", IceCandidateType::kHost, kCandidateGeneration,
kCandidateFoundation1);
std::unique_ptr<IceCandidateInterface> jcandidate_template(
new JsepIceCandidate(std::string("audio_content_name"), 0, candidate));