summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/p2p
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /third_party/libwebrtc/p2p
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/p2p')
-rw-r--r--third_party/libwebrtc/p2p/base/basic_ice_controller.cc6
-rw-r--r--third_party/libwebrtc/p2p/base/basic_ice_controller.h3
-rw-r--r--third_party/libwebrtc/p2p/base/connection.cc9
-rw-r--r--third_party/libwebrtc/p2p/base/ice_controller_interface.h15
-rw-r--r--third_party/libwebrtc/p2p/base/mock_ice_controller.h4
-rw-r--r--third_party/libwebrtc/p2p/base/p2p_transport_channel.cc50
-rw-r--r--third_party/libwebrtc/p2p/base/p2p_transport_channel.h4
-rw-r--r--third_party/libwebrtc/p2p/base/p2p_transport_channel_unittest.cc119
-rw-r--r--third_party/libwebrtc/p2p/base/port.cc7
-rw-r--r--third_party/libwebrtc/p2p/base/port.h5
-rw-r--r--third_party/libwebrtc/p2p/base/port_allocator.cc9
-rw-r--r--third_party/libwebrtc/p2p/base/port_unittest.cc91
-rw-r--r--third_party/libwebrtc/p2p/base/pseudo_tcp.cc5
-rw-r--r--third_party/libwebrtc/p2p/base/stun_dictionary.cc3
-rw-r--r--third_party/libwebrtc/p2p/base/stun_port.cc4
-rw-r--r--third_party/libwebrtc/p2p/base/stun_port_unittest.cc8
-rw-r--r--third_party/libwebrtc/p2p/base/stun_server_unittest.cc3
-rw-r--r--third_party/libwebrtc/p2p/base/turn_port.cc26
-rw-r--r--third_party/libwebrtc/p2p/base/turn_port.h9
-rw-r--r--third_party/libwebrtc/p2p/base/turn_port_unittest.cc3
-rw-r--r--third_party/libwebrtc/p2p/base/turn_server.cc3
-rw-r--r--third_party/libwebrtc/p2p/client/basic_port_allocator.cc35
-rw-r--r--third_party/libwebrtc/p2p/client/basic_port_allocator.h3
-rw-r--r--third_party/libwebrtc/p2p/client/basic_port_allocator_unittest.cc28
-rw-r--r--third_party/libwebrtc/p2p/stunprober/stun_prober.cc4
25 files changed, 165 insertions, 291 deletions
diff --git a/third_party/libwebrtc/p2p/base/basic_ice_controller.cc b/third_party/libwebrtc/p2p/base/basic_ice_controller.cc
index a0ff4cf144..182845cdd7 100644
--- a/third_party/libwebrtc/p2p/base/basic_ice_controller.cc
+++ b/third_party/libwebrtc/p2p/base/basic_ice_controller.cc
@@ -565,9 +565,9 @@ bool BasicIceController::ReadyToSend(const Connection* connection) const {
bool BasicIceController::PresumedWritable(const Connection* conn) const {
return (conn->write_state() == Connection::STATE_WRITE_INIT &&
config_.presume_writable_when_fully_relayed &&
- conn->local_candidate().type() == RELAY_PORT_TYPE &&
- (conn->remote_candidate().type() == RELAY_PORT_TYPE ||
- conn->remote_candidate().type() == PRFLX_PORT_TYPE));
+ conn->local_candidate().is_relay() &&
+ (conn->remote_candidate().is_relay() ||
+ conn->remote_candidate().is_prflx()));
}
// Compare two connections based on their writing, receiving, and connected
diff --git a/third_party/libwebrtc/p2p/base/basic_ice_controller.h b/third_party/libwebrtc/p2p/base/basic_ice_controller.h
index b941a0dd7e..724609d2d7 100644
--- a/third_party/libwebrtc/p2p/base/basic_ice_controller.h
+++ b/third_party/libwebrtc/p2p/base/basic_ice_controller.h
@@ -32,6 +32,9 @@ class BasicIceController : public IceControllerInterface {
void SetSelectedConnection(const Connection* selected_connection) override;
void AddConnection(const Connection* connection) override;
void OnConnectionDestroyed(const Connection* connection) override;
+ rtc::ArrayView<const Connection* const> GetConnections() const override {
+ return connections_;
+ }
rtc::ArrayView<const Connection*> connections() const override {
return rtc::ArrayView<const Connection*>(
const_cast<const Connection**>(connections_.data()),
diff --git a/third_party/libwebrtc/p2p/base/connection.cc b/third_party/libwebrtc/p2p/base/connection.cc
index d0e6f1bff8..bf07dec607 100644
--- a/third_party/libwebrtc/p2p/base/connection.cc
+++ b/third_party/libwebrtc/p2p/base/connection.cc
@@ -590,10 +590,8 @@ void Connection::HandleStunBindingOrGoogPingRequest(IceMessage* msg) {
// This connection should now be receiving.
ReceivedPing(msg->transaction_id());
if (field_trials_->extra_ice_ping && last_ping_response_received_ == 0) {
- if (local_candidate().type() == RELAY_PORT_TYPE ||
- local_candidate().type() == PRFLX_PORT_TYPE ||
- remote_candidate().type() == RELAY_PORT_TYPE ||
- remote_candidate().type() == PRFLX_PORT_TYPE) {
+ if (local_candidate().is_relay() || local_candidate().is_prflx() ||
+ remote_candidate().is_relay() || remote_candidate().is_prflx()) {
const int64_t now = rtc::TimeMillis();
if (last_ping_sent_ + kMinExtraPingDelayMs <= now) {
RTC_LOG(LS_INFO) << ToString()
@@ -1579,8 +1577,7 @@ void Connection::MaybeSetRemoteIceParametersAndGeneration(
void Connection::MaybeUpdatePeerReflexiveCandidate(
const Candidate& new_candidate) {
- if (remote_candidate_.type() == PRFLX_PORT_TYPE &&
- new_candidate.type() != PRFLX_PORT_TYPE &&
+ if (remote_candidate_.is_prflx() && !new_candidate.is_prflx() &&
remote_candidate_.protocol() == new_candidate.protocol() &&
remote_candidate_.address() == new_candidate.address() &&
remote_candidate_.username() == new_candidate.username() &&
diff --git a/third_party/libwebrtc/p2p/base/ice_controller_interface.h b/third_party/libwebrtc/p2p/base/ice_controller_interface.h
index 8b63ed3fc3..fb421cf0f9 100644
--- a/third_party/libwebrtc/p2p/base/ice_controller_interface.h
+++ b/third_party/libwebrtc/p2p/base/ice_controller_interface.h
@@ -19,6 +19,7 @@
#include "p2p/base/connection.h"
#include "p2p/base/ice_switch_reason.h"
#include "p2p/base/ice_transport_internal.h"
+#include "rtc_base/checks.h"
#include "rtc_base/system/rtc_export.h"
namespace cricket {
@@ -53,7 +54,7 @@ struct RTC_EXPORT IceRecheckEvent {
// Connection::ForgetLearnedState - return in SwitchResult
//
// The IceController shall keep track of all connections added
-// (and not destroyed) and give them back using the connections()-function-
+// (and not destroyed) and give them back using the GetConnections() function.
//
// When a Connection gets destroyed
// - signals on Connection::SignalDestroyed
@@ -101,7 +102,17 @@ class IceControllerInterface {
virtual void OnConnectionDestroyed(const Connection* connection) = 0;
// These are all connections that has been added and not destroyed.
- virtual rtc::ArrayView<const Connection*> connections() const = 0;
+ virtual rtc::ArrayView<const Connection* const> GetConnections() const {
+ // Stub implementation to simplify downstream roll.
+ RTC_CHECK_NOTREACHED();
+ return {};
+ }
+ // TODO(bugs.webrtc.org/15702): Remove this after downstream is cleaned up.
+ virtual rtc::ArrayView<const Connection*> connections() const {
+ // Stub implementation to simplify downstream removal.
+ RTC_CHECK_NOTREACHED();
+ return {};
+ }
// Is there a pingable connection ?
// This function is used to boot-strap pinging, after this returns true
diff --git a/third_party/libwebrtc/p2p/base/mock_ice_controller.h b/third_party/libwebrtc/p2p/base/mock_ice_controller.h
index bde9254e7d..f552519be0 100644
--- a/third_party/libwebrtc/p2p/base/mock_ice_controller.h
+++ b/third_party/libwebrtc/p2p/base/mock_ice_controller.h
@@ -35,6 +35,10 @@ class MockIceController : public cricket::IceControllerInterface {
OnConnectionDestroyed,
(const cricket::Connection*),
(override));
+ MOCK_METHOD(rtc::ArrayView<const cricket::Connection* const>,
+ GetConnections,
+ (),
+ (const, override));
MOCK_METHOD(rtc::ArrayView<const cricket::Connection*>,
connections,
(),
diff --git a/third_party/libwebrtc/p2p/base/p2p_transport_channel.cc b/third_party/libwebrtc/p2p/base/p2p_transport_channel.cc
index 0c869ff622..35d7f85d69 100644
--- a/third_party/libwebrtc/p2p/base/p2p_transport_channel.cc
+++ b/third_party/libwebrtc/p2p/base/p2p_transport_channel.cc
@@ -872,20 +872,6 @@ void P2PTransportChannel::MaybeStartGathering() {
SendGatheringStateEvent();
}
- if (!allocator_sessions_.empty()) {
- IceRestartState state;
- if (writable()) {
- state = IceRestartState::CONNECTED;
- } else if (IsGettingPorts()) {
- state = IceRestartState::CONNECTING;
- } else {
- state = IceRestartState::DISCONNECTED;
- }
- RTC_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.IceRestartState",
- static_cast<int>(state),
- static_cast<int>(IceRestartState::MAX_VALUE));
- }
-
for (const auto& session : allocator_sessions_) {
if (session->IsStopped()) {
continue;
@@ -1430,8 +1416,7 @@ bool P2PTransportChannel::CreateConnection(PortInterface* port,
if (ice_field_trials_.skip_relay_to_non_relay_connections) {
if ((port->Type() != remote_candidate.type()) &&
- (port->Type() == RELAY_PORT_TYPE ||
- remote_candidate.type() == RELAY_PORT_TYPE)) {
+ (port->Type() == RELAY_PORT_TYPE || remote_candidate.is_relay())) {
RTC_LOG(LS_INFO) << ToString() << ": skip creating connection "
<< port->Type() << " to " << remote_candidate.type();
return false;
@@ -1722,9 +1707,9 @@ bool P2PTransportChannel::PresumedWritable(const Connection* conn) const {
RTC_DCHECK_RUN_ON(network_thread_);
return (conn->write_state() == Connection::STATE_WRITE_INIT &&
config_.presume_writable_when_fully_relayed &&
- conn->local_candidate().type() == RELAY_PORT_TYPE &&
- (conn->remote_candidate().type() == RELAY_PORT_TYPE ||
- conn->remote_candidate().type() == PRFLX_PORT_TYPE));
+ conn->local_candidate().is_relay() &&
+ (conn->remote_candidate().is_relay() ||
+ conn->remote_candidate().is_prflx()));
}
void P2PTransportChannel::UpdateState() {
@@ -1771,19 +1756,18 @@ bool P2PTransportChannel::PruneConnections(
rtc::NetworkRoute P2PTransportChannel::ConfigureNetworkRoute(
const Connection* conn) {
RTC_DCHECK_RUN_ON(network_thread_);
- return {
- .connected = ReadyToSend(conn),
- .local = CreateRouteEndpointFromCandidate(
- /* local= */ true, conn->local_candidate(),
- /* uses_turn= */
- conn->port()->Type() == RELAY_PORT_TYPE),
- .remote = CreateRouteEndpointFromCandidate(
- /* local= */ false, conn->remote_candidate(),
- /* uses_turn= */ conn->remote_candidate().type() == RELAY_PORT_TYPE),
- .last_sent_packet_id = last_sent_packet_id_,
- .packet_overhead =
- conn->local_candidate().address().ipaddr().overhead() +
- GetProtocolOverhead(conn->local_candidate().protocol())};
+ return {.connected = ReadyToSend(conn),
+ .local = CreateRouteEndpointFromCandidate(
+ /* local= */ true, conn->local_candidate(),
+ /* uses_turn= */
+ conn->port()->Type() == RELAY_PORT_TYPE),
+ .remote = CreateRouteEndpointFromCandidate(
+ /* local= */ false, conn->remote_candidate(),
+ /* uses_turn= */ conn->remote_candidate().is_relay()),
+ .last_sent_packet_id = last_sent_packet_id_,
+ .packet_overhead =
+ conn->local_candidate().address().ipaddr().overhead() +
+ GetProtocolOverhead(conn->local_candidate().protocol())};
}
void P2PTransportChannel::SwitchSelectedConnection(
@@ -2294,7 +2278,7 @@ Candidate P2PTransportChannel::SanitizeRemoteCandidate(
bool use_hostname_address = absl::EndsWith(c.address().hostname(), LOCAL_TLD);
// Remove the address for prflx remote candidates. See
// https://w3c.github.io/webrtc-stats/#dom-rtcicecandidatestats.
- use_hostname_address |= c.type() == PRFLX_PORT_TYPE;
+ use_hostname_address |= c.is_prflx();
return c.ToSanitizedCopy(use_hostname_address,
false /* filter_related_address */);
}
diff --git a/third_party/libwebrtc/p2p/base/p2p_transport_channel.h b/third_party/libwebrtc/p2p/base/p2p_transport_channel.h
index 84325b8bef..47f37c8c67 100644
--- a/third_party/libwebrtc/p2p/base/p2p_transport_channel.h
+++ b/third_party/libwebrtc/p2p/base/p2p_transport_channel.h
@@ -79,10 +79,6 @@ class RtcEventLog;
namespace cricket {
-// Enum for UMA metrics, used to record whether the channel is
-// connected/connecting/disconnected when ICE restart happens.
-enum class IceRestartState { CONNECTING, CONNECTED, DISCONNECTED, MAX_VALUE };
-
static const int MIN_PINGS_AT_WEAK_PING_INTERVAL = 3;
bool IceCredentialsChanged(absl::string_view old_ufrag,
diff --git a/third_party/libwebrtc/p2p/base/p2p_transport_channel_unittest.cc b/third_party/libwebrtc/p2p/base/p2p_transport_channel_unittest.cc
index 44b1bfc5e3..a0446c7965 100644
--- a/third_party/libwebrtc/p2p/base/p2p_transport_channel_unittest.cc
+++ b/third_party/libwebrtc/p2p/base/p2p_transport_channel_unittest.cc
@@ -1478,93 +1478,7 @@ TEST_F(P2PTransportChannelTest, GetStatsSwitchConnection) {
DestroyChannels();
}
-// Tests that UMAs are recorded when ICE restarts while the channel
-// is disconnected.
-TEST_F(P2PTransportChannelTest, TestUMAIceRestartWhileDisconnected) {
- rtc::ScopedFakeClock clock;
- ConfigureEndpoints(OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts);
-
- CreateChannels();
- EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()),
- kDefaultTimeout, clock);
-
- // Drop all packets so that both channels become not writable.
- fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]);
- const int kWriteTimeoutDelay = 8000;
- EXPECT_TRUE_SIMULATED_WAIT(!ep1_ch1()->writable() && !ep2_ch1()->writable(),
- kWriteTimeoutDelay, clock);
-
- ep1_ch1()->SetIceParameters(kIceParams[2]);
- ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
- ep1_ch1()->MaybeStartGathering();
- EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(
- "WebRTC.PeerConnection.IceRestartState",
- static_cast<int>(IceRestartState::DISCONNECTED)));
-
- ep2_ch1()->SetIceParameters(kIceParams[3]);
- ep2_ch1()->SetRemoteIceParameters(kIceParams[2]);
- ep2_ch1()->MaybeStartGathering();
- EXPECT_METRIC_EQ(2, webrtc::metrics::NumEvents(
- "WebRTC.PeerConnection.IceRestartState",
- static_cast<int>(IceRestartState::DISCONNECTED)));
-
- DestroyChannels();
-}
-
-// Tests that UMAs are recorded when ICE restarts while the channel
-// is connected.
-TEST_F(P2PTransportChannelTest, TestUMAIceRestartWhileConnected) {
- rtc::ScopedFakeClock clock;
- ConfigureEndpoints(OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts);
-
- CreateChannels();
- EXPECT_TRUE_SIMULATED_WAIT(CheckConnected(ep1_ch1(), ep2_ch1()),
- kDefaultTimeout, clock);
-
- ep1_ch1()->SetIceParameters(kIceParams[2]);
- ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
- ep1_ch1()->MaybeStartGathering();
- EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(
- "WebRTC.PeerConnection.IceRestartState",
- static_cast<int>(IceRestartState::CONNECTED)));
-
- ep2_ch1()->SetIceParameters(kIceParams[3]);
- ep2_ch1()->SetRemoteIceParameters(kIceParams[2]);
- ep2_ch1()->MaybeStartGathering();
- EXPECT_METRIC_EQ(2, webrtc::metrics::NumEvents(
- "WebRTC.PeerConnection.IceRestartState",
- static_cast<int>(IceRestartState::CONNECTED)));
-
- DestroyChannels();
-}
-
-// Tests that UMAs are recorded when ICE restarts while the channel
-// is connecting.
-TEST_F(P2PTransportChannelTest, TestUMAIceRestartWhileConnecting) {
- rtc::ScopedFakeClock clock;
- ConfigureEndpoints(OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts);
-
- // Create the channels without waiting for them to become connected.
- CreateChannels();
-
- ep1_ch1()->SetIceParameters(kIceParams[2]);
- ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
- ep1_ch1()->MaybeStartGathering();
- EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(
- "WebRTC.PeerConnection.IceRestartState",
- static_cast<int>(IceRestartState::CONNECTING)));
-
- ep2_ch1()->SetIceParameters(kIceParams[3]);
- ep2_ch1()->SetRemoteIceParameters(kIceParams[2]);
- ep2_ch1()->MaybeStartGathering();
- EXPECT_METRIC_EQ(2, webrtc::metrics::NumEvents(
- "WebRTC.PeerConnection.IceRestartState",
- static_cast<int>(IceRestartState::CONNECTING)));
-
- DestroyChannels();
-}
-
-// Tests that a UMA on ICE regathering is recorded when there is a network
+// Tests that an ICE regathering reason is recorded when there is a network
// change if and only if continual gathering is enabled.
TEST_F(P2PTransportChannelTest,
TestIceRegatheringReasonContinualGatheringByNetworkChange) {
@@ -1600,7 +1514,7 @@ TEST_F(P2PTransportChannelTest,
DestroyChannels();
}
-// Tests that a UMA on ICE regathering is recorded when there is a network
+// Tests that an ICE regathering reason is recorded when there is a network
// failure if and only if continual gathering is enabled.
TEST_F(P2PTransportChannelTest,
TestIceRegatheringReasonContinualGatheringByNetworkFailure) {
@@ -1623,10 +1537,6 @@ TEST_F(P2PTransportChannelTest,
SIMULATED_WAIT(false, kNetworkFailureTimeout, clock);
EXPECT_LE(1, GetEndpoint(0)->GetIceRegatheringCountForReason(
IceRegatheringReason::NETWORK_FAILURE));
- EXPECT_METRIC_LE(
- 1, webrtc::metrics::NumEvents(
- "WebRTC.PeerConnection.IceRegatheringReason",
- static_cast<int>(IceRegatheringReason::NETWORK_FAILURE)));
EXPECT_EQ(0, GetEndpoint(1)->GetIceRegatheringCountForReason(
IceRegatheringReason::NETWORK_FAILURE));
@@ -3601,7 +3511,8 @@ class P2PTransportChannelPingTest : public ::testing::Test,
rtc::ByteBufferWriter buf;
msg.Write(&buf);
conn->OnReadPacket(rtc::ReceivedPacket::CreateFromLegacy(
- buf.Data(), buf.Length(), rtc::TimeMicros()));
+ reinterpret_cast<const char*>(buf.Data()), buf.Length(),
+ rtc::TimeMicros()));
}
void ReceivePingOnConnection(Connection* conn,
@@ -5097,7 +5008,7 @@ class P2PTransportChannelMostLikelyToWorkFirstTest
Connection* conn = FindNextPingableConnectionAndPingIt(channel_.get());
ASSERT_TRUE(conn != nullptr);
EXPECT_EQ(conn->local_candidate().type(), local_candidate_type);
- if (conn->local_candidate().type() == RELAY_PORT_TYPE) {
+ if (conn->local_candidate().is_relay()) {
EXPECT_EQ(conn->local_candidate().relay_protocol(), relay_protocol_type);
}
EXPECT_EQ(conn->remote_candidate().type(), remote_candidate_type);
@@ -5509,7 +5420,7 @@ TEST_F(P2PTransportChannelTest,
for (const auto& candidates_data : GetEndpoint(0)->saved_candidates_) {
const auto& local_candidate_ep1 = candidates_data.candidate;
- if (local_candidate_ep1.type() == LOCAL_PORT_TYPE) {
+ if (local_candidate_ep1.is_local()) {
// This is the underlying private IP address of the same candidate at ep1,
// and let the mock resolver of ep2 receive the correct resolution.
rtc::SocketAddress resolved_address_ep1(local_candidate_ep1.address());
@@ -5538,11 +5449,11 @@ TEST_F(P2PTransportChannelTest,
// Check the stats of ep1 seen by ep1.
for (const auto& connection_info : ice_transport_stats1.connection_infos) {
const auto& local_candidate = connection_info.local_candidate;
- if (local_candidate.type() == LOCAL_PORT_TYPE) {
+ if (local_candidate.is_local()) {
EXPECT_TRUE(local_candidate.address().IsUnresolvedIP());
- } else if (local_candidate.type() == STUN_PORT_TYPE) {
+ } else if (local_candidate.is_stun()) {
EXPECT_TRUE(local_candidate.related_address().IsAnyIP());
- } else if (local_candidate.type() == RELAY_PORT_TYPE) {
+ } else if (local_candidate.is_relay()) {
// The related address of the relay candidate should be equal to the
// srflx address. Note that NAT is not configured, hence the following
// expectation.
@@ -5555,11 +5466,11 @@ TEST_F(P2PTransportChannelTest,
// Check the stats of ep1 seen by ep2.
for (const auto& connection_info : ice_transport_stats2.connection_infos) {
const auto& remote_candidate = connection_info.remote_candidate;
- if (remote_candidate.type() == LOCAL_PORT_TYPE) {
+ if (remote_candidate.is_local()) {
EXPECT_TRUE(remote_candidate.address().IsUnresolvedIP());
- } else if (remote_candidate.type() == STUN_PORT_TYPE) {
+ } else if (remote_candidate.is_stun()) {
EXPECT_TRUE(remote_candidate.related_address().IsAnyIP());
- } else if (remote_candidate.type() == RELAY_PORT_TYPE) {
+ } else if (remote_candidate.is_relay()) {
EXPECT_EQ(kPublicAddrs[0].ipaddr(),
remote_candidate.related_address().ipaddr());
} else {
@@ -5681,7 +5592,7 @@ TEST_F(P2PTransportChannelTest,
ASSERT_EQ_WAIT(1u, GetEndpoint(0)->saved_candidates_.size(), kMediumTimeout);
const auto& candidates_data = GetEndpoint(0)->saved_candidates_[0];
const auto& local_candidate_ep1 = candidates_data.candidate;
- ASSERT_TRUE(local_candidate_ep1.type() == LOCAL_PORT_TYPE);
+ ASSERT_TRUE(local_candidate_ep1.is_local());
// This is the underlying private IP address of the same candidate at ep1,
// and let the mock resolver of ep2 receive the correct resolution.
rtc::SocketAddress resolved_address_ep1(local_candidate_ep1.address());
@@ -5697,12 +5608,12 @@ TEST_F(P2PTransportChannelTest,
const auto pair_ep1 = ep1_ch1()->GetSelectedCandidatePair();
ASSERT_TRUE(pair_ep1.has_value());
- EXPECT_EQ(LOCAL_PORT_TYPE, pair_ep1->local_candidate().type());
+ EXPECT_TRUE(pair_ep1->local_candidate().is_local());
EXPECT_TRUE(pair_ep1->local_candidate().address().IsUnresolvedIP());
const auto pair_ep2 = ep2_ch1()->GetSelectedCandidatePair();
ASSERT_TRUE(pair_ep2.has_value());
- EXPECT_EQ(LOCAL_PORT_TYPE, pair_ep2->remote_candidate().type());
+ EXPECT_TRUE(pair_ep2->remote_candidate().is_local());
EXPECT_TRUE(pair_ep2->remote_candidate().address().IsUnresolvedIP());
DestroyChannels();
diff --git a/third_party/libwebrtc/p2p/base/port.cc b/third_party/libwebrtc/p2p/base/port.cc
index 3069799f7b..a3378fe23a 100644
--- a/third_party/libwebrtc/p2p/base/port.cc
+++ b/third_party/libwebrtc/p2p/base/port.cc
@@ -69,13 +69,6 @@ const int kPortTimeoutDelay = cricket::STUN_TOTAL_TIMEOUT + 5000;
} // namespace
-// TODO(ronghuawu): Use "local", "srflx", "prflx" and "relay". But this requires
-// the signaling part be updated correspondingly as well.
-const char LOCAL_PORT_TYPE[] = "local";
-const char STUN_PORT_TYPE[] = "stun";
-const char PRFLX_PORT_TYPE[] = "prflx";
-const char RELAY_PORT_TYPE[] = "relay";
-
static const char* const PROTO_NAMES[] = {UDP_PROTOCOL_NAME, TCP_PROTOCOL_NAME,
SSLTCP_PROTOCOL_NAME,
TLS_PROTOCOL_NAME};
diff --git a/third_party/libwebrtc/p2p/base/port.h b/third_party/libwebrtc/p2p/base/port.h
index 796e1e1d5b..7b44e534de 100644
--- a/third_party/libwebrtc/p2p/base/port.h
+++ b/third_party/libwebrtc/p2p/base/port.h
@@ -53,11 +53,6 @@
namespace cricket {
-RTC_EXPORT extern const char LOCAL_PORT_TYPE[];
-RTC_EXPORT extern const char STUN_PORT_TYPE[];
-RTC_EXPORT extern const char PRFLX_PORT_TYPE[];
-RTC_EXPORT extern const char RELAY_PORT_TYPE[];
-
// RFC 6544, TCP candidate encoding rules.
extern const int DISCARD_PORT;
extern const char TCPTYPE_ACTIVE_STR[];
diff --git a/third_party/libwebrtc/p2p/base/port_allocator.cc b/third_party/libwebrtc/p2p/base/port_allocator.cc
index 9292319b56..16f5afe36c 100644
--- a/third_party/libwebrtc/p2p/base/port_allocator.cc
+++ b/third_party/libwebrtc/p2p/base/port_allocator.cc
@@ -312,8 +312,7 @@ Candidate PortAllocator::SanitizeCandidate(const Candidate& c) const {
// For a local host candidate, we need to conceal its IP address candidate if
// the mDNS obfuscation is enabled.
bool use_hostname_address =
- (c.type() == LOCAL_PORT_TYPE || c.type() == PRFLX_PORT_TYPE) &&
- MdnsObfuscationEnabled();
+ (c.is_local() || c.is_prflx()) && MdnsObfuscationEnabled();
// If adapter enumeration is disabled or host candidates are disabled,
// clear the raddr of STUN candidates to avoid local address leakage.
bool filter_stun_related_address =
@@ -326,9 +325,9 @@ Candidate PortAllocator::SanitizeCandidate(const Candidate& c) const {
// Sanitize related_address when using MDNS.
bool filter_prflx_related_address = MdnsObfuscationEnabled();
bool filter_related_address =
- ((c.type() == STUN_PORT_TYPE && filter_stun_related_address) ||
- (c.type() == RELAY_PORT_TYPE && filter_turn_related_address) ||
- (c.type() == PRFLX_PORT_TYPE && filter_prflx_related_address));
+ ((c.is_stun() && filter_stun_related_address) ||
+ (c.is_relay() && filter_turn_related_address) ||
+ (c.is_prflx() && filter_prflx_related_address));
return c.ToSanitizedCopy(use_hostname_address, filter_related_address);
}
diff --git a/third_party/libwebrtc/p2p/base/port_unittest.cc b/third_party/libwebrtc/p2p/base/port_unittest.cc
index 96c1bd5ee1..de35d94259 100644
--- a/third_party/libwebrtc/p2p/base/port_unittest.cc
+++ b/third_party/libwebrtc/p2p/base/port_unittest.cc
@@ -257,6 +257,15 @@ class TestPort : public Port {
int type_preference_ = 0;
};
+bool GetStunMessageFromBufferWriter(TestPort* port,
+ ByteBufferWriter* buf,
+ const rtc::SocketAddress& addr,
+ std::unique_ptr<IceMessage>* out_msg,
+ std::string* out_username) {
+ return port->GetStunMessage(reinterpret_cast<const char*>(buf->Data()),
+ buf->Length(), addr, out_msg, out_username);
+}
+
static void SendPingAndReceiveResponse(Connection* lconn,
TestPort* lport,
Connection* rconn,
@@ -620,8 +629,8 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> {
std::unique_ptr<rtc::NATServer> CreateNatServer(const SocketAddress& addr,
rtc::NATType type) {
- return std::make_unique<rtc::NATServer>(type, ss_.get(), addr, addr,
- ss_.get(), addr);
+ return std::make_unique<rtc::NATServer>(type, main_, ss_.get(), addr, addr,
+ main_, ss_.get(), addr);
}
static const char* StunName(NATType type) {
switch (type) {
@@ -1529,7 +1538,8 @@ TEST_F(PortTest, TestLoopbackCall) {
auto buf = std::make_unique<ByteBufferWriter>();
WriteStunMessage(*modified_req, buf.get());
conn1->OnReadPacket(rtc::ReceivedPacket::CreateFromLegacy(
- buf->Data(), buf->Length(), /*packet_time_us=*/-1));
+ reinterpret_cast<const char*>(buf->Data()), buf->Length(),
+ /*packet_time_us=*/-1));
ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout);
msg = lport->last_stun_msg();
EXPECT_EQ(STUN_BINDING_ERROR_RESPONSE, msg->type());
@@ -2247,8 +2257,8 @@ TEST_F(PortTest, TestHandleStunMessage) {
in_msg->AddMessageIntegrity("rpass");
in_msg->AddFingerprint();
WriteStunMessage(*in_msg, buf.get());
- EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_TRUE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_TRUE(out_msg.get() != NULL);
EXPECT_EQ("lfrag", username);
@@ -2259,8 +2269,8 @@ TEST_F(PortTest, TestHandleStunMessage) {
in_msg->AddMessageIntegrity("rpass");
in_msg->AddFingerprint();
WriteStunMessage(*in_msg, buf.get());
- EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_TRUE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_TRUE(out_msg.get() != NULL);
EXPECT_EQ("", username);
@@ -2271,8 +2281,8 @@ TEST_F(PortTest, TestHandleStunMessage) {
STUN_ERROR_REASON_SERVER_ERROR));
in_msg->AddFingerprint();
WriteStunMessage(*in_msg, buf.get());
- EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_TRUE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_TRUE(out_msg.get() != NULL);
EXPECT_EQ("", username);
ASSERT_TRUE(out_msg->GetErrorCode() != NULL);
@@ -2295,8 +2305,8 @@ TEST_F(PortTest, TestHandleStunMessageBadUsername) {
in_msg->AddMessageIntegrity("rpass");
in_msg->AddFingerprint();
WriteStunMessage(*in_msg, buf.get());
- EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_TRUE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_TRUE(out_msg.get() == NULL);
EXPECT_EQ("", username);
EXPECT_EQ(STUN_ERROR_BAD_REQUEST, port->last_stun_error_code());
@@ -2306,8 +2316,8 @@ TEST_F(PortTest, TestHandleStunMessageBadUsername) {
in_msg->AddMessageIntegrity("rpass");
in_msg->AddFingerprint();
WriteStunMessage(*in_msg, buf.get());
- EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_TRUE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_TRUE(out_msg.get() == NULL);
EXPECT_EQ("", username);
EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code());
@@ -2317,8 +2327,8 @@ TEST_F(PortTest, TestHandleStunMessageBadUsername) {
in_msg->AddMessageIntegrity("rpass");
in_msg->AddFingerprint();
WriteStunMessage(*in_msg, buf.get());
- EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_TRUE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_TRUE(out_msg.get() == NULL);
EXPECT_EQ("", username);
EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code());
@@ -2328,8 +2338,8 @@ TEST_F(PortTest, TestHandleStunMessageBadUsername) {
in_msg->AddMessageIntegrity("rpass");
in_msg->AddFingerprint();
WriteStunMessage(*in_msg, buf.get());
- EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_TRUE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_TRUE(out_msg.get() == NULL);
EXPECT_EQ("", username);
EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code());
@@ -2339,8 +2349,8 @@ TEST_F(PortTest, TestHandleStunMessageBadUsername) {
in_msg->AddMessageIntegrity("rpass");
in_msg->AddFingerprint();
WriteStunMessage(*in_msg, buf.get());
- EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_TRUE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_TRUE(out_msg.get() == NULL);
EXPECT_EQ("", username);
EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code());
@@ -2361,8 +2371,8 @@ TEST_F(PortTest, TestHandleStunMessageBadMessageIntegrity) {
in_msg = CreateStunMessageWithUsername(STUN_BINDING_REQUEST, "rfrag:lfrag");
in_msg->AddFingerprint();
WriteStunMessage(*in_msg, buf.get());
- EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_TRUE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_TRUE(out_msg.get() == NULL);
EXPECT_EQ("", username);
EXPECT_EQ(STUN_ERROR_BAD_REQUEST, port->last_stun_error_code());
@@ -2373,8 +2383,8 @@ TEST_F(PortTest, TestHandleStunMessageBadMessageIntegrity) {
in_msg->AddMessageIntegrity("invalid");
in_msg->AddFingerprint();
WriteStunMessage(*in_msg, buf.get());
- EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_TRUE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_TRUE(out_msg.get() == NULL);
EXPECT_EQ("", username);
EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code());
@@ -2399,16 +2409,16 @@ TEST_F(PortTest, TestHandleStunMessageBadFingerprint) {
in_msg = CreateStunMessageWithUsername(STUN_BINDING_REQUEST, "rfrag:lfrag");
in_msg->AddMessageIntegrity("rpass");
WriteStunMessage(*in_msg, buf.get());
- EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_FALSE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_EQ(0, port->last_stun_error_code());
// Now, add a fingerprint, but munge the message so it's not valid.
in_msg->AddFingerprint();
in_msg->SetTransactionIdForTesting("TESTTESTBADD");
WriteStunMessage(*in_msg, buf.get());
- EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_FALSE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_EQ(0, port->last_stun_error_code());
// Valid BINDING-RESPONSE, except no FINGERPRINT.
@@ -2417,16 +2427,16 @@ TEST_F(PortTest, TestHandleStunMessageBadFingerprint) {
STUN_ATTR_XOR_MAPPED_ADDRESS, kLocalAddr2));
in_msg->AddMessageIntegrity("rpass");
WriteStunMessage(*in_msg, buf.get());
- EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_FALSE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_EQ(0, port->last_stun_error_code());
// Now, add a fingerprint, but munge the message so it's not valid.
in_msg->AddFingerprint();
in_msg->SetTransactionIdForTesting("TESTTESTBADD");
WriteStunMessage(*in_msg, buf.get());
- EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_FALSE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_EQ(0, port->last_stun_error_code());
// Valid BINDING-ERROR-RESPONSE, except no FINGERPRINT.
@@ -2436,16 +2446,16 @@ TEST_F(PortTest, TestHandleStunMessageBadFingerprint) {
STUN_ERROR_REASON_SERVER_ERROR));
in_msg->AddMessageIntegrity("rpass");
WriteStunMessage(*in_msg, buf.get());
- EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_FALSE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_EQ(0, port->last_stun_error_code());
// Now, add a fingerprint, but munge the message so it's not valid.
in_msg->AddFingerprint();
in_msg->SetTransactionIdForTesting("TESTTESTBADD");
WriteStunMessage(*in_msg, buf.get());
- EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_FALSE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_EQ(0, port->last_stun_error_code());
}
@@ -2472,8 +2482,8 @@ TEST_F(PortTest,
in_msg->AddAttribute(StunAttribute::CreateUInt32(0xdead));
in_msg->AddFingerprint();
WriteStunMessage(*in_msg, buf.get());
- ASSERT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ ASSERT_TRUE(GetStunMessageFromBufferWriter(port.get(), buf.get(), addr,
+ &out_msg, &username));
IceMessage* error_response = port->last_stun_msg();
ASSERT_NE(nullptr, error_response);
@@ -2522,7 +2532,8 @@ TEST_F(PortTest,
ByteBufferWriter buf;
WriteStunMessage(*modified_response, &buf);
lconn->OnReadPacket(rtc::ReceivedPacket::CreateFromLegacy(
- buf.Data(), buf.Length(), /*packet_time_us=*/-1));
+ reinterpret_cast<const char*>(buf.Data()), buf.Length(),
+ /*packet_time_us=*/-1));
// Response should have been ignored, leaving us unwritable still.
EXPECT_FALSE(lconn->writable());
}
@@ -2570,8 +2581,8 @@ TEST_F(PortTest, TestHandleStunBindingIndication) {
in_msg = CreateStunMessage(STUN_BINDING_INDICATION);
in_msg->AddFingerprint();
WriteStunMessage(*in_msg, buf.get());
- EXPECT_TRUE(lport->GetStunMessage(buf->Data(), buf->Length(), addr, &out_msg,
- &username));
+ EXPECT_TRUE(GetStunMessageFromBufferWriter(lport.get(), buf.get(), addr,
+ &out_msg, &username));
EXPECT_TRUE(out_msg.get() != NULL);
EXPECT_EQ(out_msg->type(), STUN_BINDING_INDICATION);
EXPECT_EQ("", username);
diff --git a/third_party/libwebrtc/p2p/base/pseudo_tcp.cc b/third_party/libwebrtc/p2p/base/pseudo_tcp.cc
index 5a5ce0392b..3aaa2ad065 100644
--- a/third_party/libwebrtc/p2p/base/pseudo_tcp.cc
+++ b/third_party/libwebrtc/p2p/base/pseudo_tcp.cc
@@ -1183,7 +1183,8 @@ void PseudoTcp::queueConnectMessage() {
buf.WriteUInt8(m_rwnd_scale);
}
m_snd_wnd = static_cast<uint32_t>(buf.Length());
- queue(buf.Data(), static_cast<uint32_t>(buf.Length()), true);
+ queue(reinterpret_cast<const char*>(buf.Data()),
+ static_cast<uint32_t>(buf.Length()), true);
}
void PseudoTcp::parseOptions(const char* data, uint32_t len) {
@@ -1212,7 +1213,7 @@ void PseudoTcp::parseOptions(const char* data, uint32_t len) {
// Content of this option.
if (opt_len <= buf.Length()) {
- applyOption(kind, buf.Data(), opt_len);
+ applyOption(kind, reinterpret_cast<const char*>(buf.Data()), opt_len);
buf.Consume(opt_len);
} else {
RTC_LOG(LS_ERROR) << "Invalid option length received.";
diff --git a/third_party/libwebrtc/p2p/base/stun_dictionary.cc b/third_party/libwebrtc/p2p/base/stun_dictionary.cc
index 318bed0ad1..aabb8c394f 100644
--- a/third_party/libwebrtc/p2p/base/stun_dictionary.cc
+++ b/third_party/libwebrtc/p2p/base/stun_dictionary.cc
@@ -214,7 +214,8 @@ StunDictionaryView::ApplyDelta(const StunByteStringAttribute& delta) {
if (attr->value_type() == STUN_VALUE_BYTE_STRING && attr->length() == 0) {
attrs_.erase(attr->type());
} else {
- attrs_[attr->type()] = std::move(attr);
+ int attribute_type = attr->type();
+ attrs_[attribute_type] = std::move(attr);
}
}
}
diff --git a/third_party/libwebrtc/p2p/base/stun_port.cc b/third_party/libwebrtc/p2p/base/stun_port.cc
index 7acaac6dbe..648933fd9e 100644
--- a/third_party/libwebrtc/p2p/base/stun_port.cc
+++ b/third_party/libwebrtc/p2p/base/stun_port.cc
@@ -285,7 +285,7 @@ Connection* UDPPort::CreateConnection(const Candidate& address,
//
// See also the definition of MdnsNameRegistrationStatus::kNotStarted in
// port.h.
- RTC_DCHECK(!SharedSocket() || Candidates()[0].type() == LOCAL_PORT_TYPE ||
+ RTC_DCHECK(!SharedSocket() || Candidates()[0].is_local() ||
mdns_name_registration_status() !=
MdnsNameRegistrationStatus::kNotStarted);
@@ -616,7 +616,7 @@ bool UDPPort::HasStunCandidateWithAddress(
const std::vector<Candidate>& existing_candidates = Candidates();
std::vector<Candidate>::const_iterator it = existing_candidates.begin();
for (; it != existing_candidates.end(); ++it) {
- if (it->type() == STUN_PORT_TYPE && it->address() == addr)
+ if (it->is_stun() && it->address() == addr)
return true;
}
return false;
diff --git a/third_party/libwebrtc/p2p/base/stun_port_unittest.cc b/third_party/libwebrtc/p2p/base/stun_port_unittest.cc
index 04505d26ff..9167081afb 100644
--- a/third_party/libwebrtc/p2p/base/stun_port_unittest.cc
+++ b/third_party/libwebrtc/p2p/base/stun_port_unittest.cc
@@ -445,11 +445,11 @@ TEST_F(StunPortTest, TestStunCandidateGeneratedWithMdnsObfuscationEnabled) {
// One of the generated candidates is a local candidate and the other is a
// stun candidate.
EXPECT_NE(port()->Candidates()[0].type(), port()->Candidates()[1].type());
- if (port()->Candidates()[0].type() == cricket::LOCAL_PORT_TYPE) {
- EXPECT_EQ(port()->Candidates()[1].type(), cricket::STUN_PORT_TYPE);
+ if (port()->Candidates()[0].is_local()) {
+ EXPECT_TRUE(port()->Candidates()[1].is_stun());
} else {
- EXPECT_EQ(port()->Candidates()[0].type(), cricket::STUN_PORT_TYPE);
- EXPECT_EQ(port()->Candidates()[1].type(), cricket::LOCAL_PORT_TYPE);
+ EXPECT_TRUE(port()->Candidates()[0].is_stun());
+ EXPECT_TRUE(port()->Candidates()[1].is_local());
}
}
diff --git a/third_party/libwebrtc/p2p/base/stun_server_unittest.cc b/third_party/libwebrtc/p2p/base/stun_server_unittest.cc
index e4ea30cba4..a2ac300b80 100644
--- a/third_party/libwebrtc/p2p/base/stun_server_unittest.cc
+++ b/third_party/libwebrtc/p2p/base/stun_server_unittest.cc
@@ -44,7 +44,8 @@ class StunServerTest : public ::testing::Test {
void Send(const StunMessage& msg) {
rtc::ByteBufferWriter buf;
msg.Write(&buf);
- Send(buf.Data(), static_cast<int>(buf.Length()));
+ Send(reinterpret_cast<const char*>(buf.Data()),
+ static_cast<int>(buf.Length()));
}
void Send(const char* buf, int len) {
client_->SendTo(buf, len, server_addr);
diff --git a/third_party/libwebrtc/p2p/base/turn_port.cc b/third_party/libwebrtc/p2p/base/turn_port.cc
index e6f5e77114..1fb3b38bfd 100644
--- a/third_party/libwebrtc/p2p/base/turn_port.cc
+++ b/third_party/libwebrtc/p2p/base/turn_port.cc
@@ -228,6 +228,7 @@ TurnPort::TurnPort(TaskQueueBase* thread,
password,
field_trials),
server_address_(server_address),
+ server_url_(ReconstructServerUrl()),
tls_alpn_protocols_(tls_alpn_protocols),
tls_elliptic_curves_(tls_elliptic_curves),
tls_cert_verifier_(tls_cert_verifier),
@@ -271,6 +272,7 @@ TurnPort::TurnPort(TaskQueueBase* thread,
password,
field_trials),
server_address_(server_address),
+ server_url_(ReconstructServerUrl()),
tls_alpn_protocols_(tls_alpn_protocols),
tls_elliptic_curves_(tls_elliptic_curves),
tls_cert_verifier_(tls_cert_verifier),
@@ -583,9 +585,8 @@ Connection* TurnPort::CreateConnection(const Candidate& remote_candidate,
// and TURN candidate later.
for (size_t index = 0; index < Candidates().size(); ++index) {
const Candidate& local_candidate = Candidates()[index];
- if (local_candidate.type() == RELAY_PORT_TYPE &&
- local_candidate.address().family() ==
- remote_candidate.address().family()) {
+ if (local_candidate.is_relay() && local_candidate.address().family() ==
+ remote_candidate.address().family()) {
ProxyConnection* conn =
new ProxyConnection(NewWeakPtr(), index, remote_candidate);
// Create an entry, if needed, so we can get our permissions set up
@@ -886,7 +887,7 @@ void TurnPort::OnAllocateSuccess(const rtc::SocketAddress& address,
ProtoToString(server_address_.proto), // The first hop protocol.
"", // TCP candidate type, empty for turn candidates.
RELAY_PORT_TYPE, GetRelayPreference(server_address_.proto),
- server_priority_, ReconstructedServerUrl(), true);
+ server_priority_, server_url_, true);
}
void TurnPort::OnAllocateError(int error_code, absl::string_view reason) {
@@ -902,9 +903,8 @@ void TurnPort::OnAllocateError(int error_code, absl::string_view reason) {
address.clear();
port = 0;
}
- SignalCandidateError(
- this, IceCandidateErrorEvent(address, port, ReconstructedServerUrl(),
- error_code, reason));
+ SignalCandidateError(this, IceCandidateErrorEvent(address, port, server_url_,
+ error_code, reason));
}
void TurnPort::OnRefreshError() {
@@ -1255,15 +1255,13 @@ bool TurnPort::SetEntryChannelId(const rtc::SocketAddress& address,
return true;
}
-std::string TurnPort::ReconstructedServerUrl() {
- // draft-petithuguenin-behave-turn-uris-01
- // turnURI = scheme ":" turn-host [ ":" turn-port ]
+std::string TurnPort::ReconstructServerUrl() {
+ // https://www.rfc-editor.org/rfc/rfc7065#section-3.1
+ // turnURI = scheme ":" host [ ":" port ]
// [ "?transport=" transport ]
// scheme = "turn" / "turns"
// transport = "udp" / "tcp" / transport-ext
// transport-ext = 1*unreserved
- // turn-host = IP-literal / IPv4address / reg-name
- // turn-port = *DIGIT
std::string scheme = "turn";
std::string transport = "tcp";
switch (server_address_.proto) {
@@ -1278,7 +1276,7 @@ std::string TurnPort::ReconstructedServerUrl() {
break;
}
rtc::StringBuilder url;
- url << scheme << ":" << server_address_.address.hostname() << ":"
+ url << scheme << ":" << server_address_.address.HostAsURIString() << ":"
<< server_address_.address.port() << "?transport=" << transport;
return url.Release();
}
@@ -1802,7 +1800,7 @@ int TurnEntry::Send(const void* data,
// If the channel is bound, we can send the data as a Channel Message.
buf.WriteUInt16(channel_id_);
buf.WriteUInt16(static_cast<uint16_t>(size));
- buf.WriteBytes(reinterpret_cast<const char*>(data), size);
+ buf.WriteBytes(reinterpret_cast<const uint8_t*>(data), size);
}
rtc::PacketOptions modified_options(options);
modified_options.info_signaled_after_sent.turn_overhead_bytes =
diff --git a/third_party/libwebrtc/p2p/base/turn_port.h b/third_party/libwebrtc/p2p/base/turn_port.h
index 686edaf595..b56f862e61 100644
--- a/third_party/libwebrtc/p2p/base/turn_port.h
+++ b/third_party/libwebrtc/p2p/base/turn_port.h
@@ -302,9 +302,6 @@ class TurnPort : public Port {
// pruned (a.k.a. write-timed-out). Returns true if a connection is found.
bool FailAndPruneConnection(const rtc::SocketAddress& address);
- // Reconstruct the URL of the server which the candidate is gathered from.
- std::string ReconstructedServerUrl();
-
void MaybeAddTurnLoggingId(StunMessage* message);
void TurnCustomizerMaybeModifyOutgoingStunMessage(StunMessage* message);
@@ -313,6 +310,12 @@ class TurnPort : public Port {
bool payload);
ProtocolAddress server_address_;
+ // Reconstruct the URL of the server which the candidate is gathered from.
+ // A copy needs to be stored as server_address_ will resolve and clear its
+ // hostname field.
+ std::string ReconstructServerUrl();
+ std::string server_url_;
+
TlsCertPolicy tls_cert_policy_ = TlsCertPolicy::TLS_CERT_POLICY_SECURE;
std::vector<std::string> tls_alpn_protocols_;
std::vector<std::string> tls_elliptic_curves_;
diff --git a/third_party/libwebrtc/p2p/base/turn_port_unittest.cc b/third_party/libwebrtc/p2p/base/turn_port_unittest.cc
index e7efb5e594..169467d76c 100644
--- a/third_party/libwebrtc/p2p/base/turn_port_unittest.cc
+++ b/third_party/libwebrtc/p2p/base/turn_port_unittest.cc
@@ -878,9 +878,10 @@ TEST_F(TurnPortTest, TestReconstructedServerUrlForUdpIPv6) {
turn_server_.AddInternalSocket(kTurnUdpIPv6IntAddr, PROTO_UDP);
CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword,
kTurnUdpIPv6ProtoAddr);
+ // Should add [] around the IPv6.
TestReconstructedServerUrl(
PROTO_UDP,
- "turn:2400:4030:1:2c00:be30:abcd:efab:cdef:3478?transport=udp");
+ "turn:[2400:4030:1:2c00:be30:abcd:efab:cdef]:3478?transport=udp");
}
TEST_F(TurnPortTest, TestReconstructedServerUrlForTcp) {
diff --git a/third_party/libwebrtc/p2p/base/turn_server.cc b/third_party/libwebrtc/p2p/base/turn_server.cc
index 3d633110a7..4e039dec24 100644
--- a/third_party/libwebrtc/p2p/base/turn_server.cc
+++ b/third_party/libwebrtc/p2p/base/turn_server.cc
@@ -784,8 +784,7 @@ void TurnServerAllocation::OnExternalPacket(rtc::AsyncPacketSocket* socket,
rtc::ByteBufferWriter buf;
buf.WriteUInt16(channel->id);
buf.WriteUInt16(static_cast<uint16_t>(packet.payload().size()));
- buf.WriteBytes(reinterpret_cast<const char*>(packet.payload().data()),
- packet.payload().size());
+ buf.WriteBytes(packet.payload().data(), packet.payload().size());
server_->Send(&conn_, buf);
} else if (!server_->enable_permission_checks_ ||
HasPermission(packet.source_address().ipaddr())) {
diff --git a/third_party/libwebrtc/p2p/client/basic_port_allocator.cc b/third_party/libwebrtc/p2p/client/basic_port_allocator.cc
index e8255f1fd5..e95033efeb 100644
--- a/third_party/libwebrtc/p2p/client/basic_port_allocator.cc
+++ b/third_party/libwebrtc/p2p/client/basic_port_allocator.cc
@@ -126,11 +126,15 @@ bool IsAllowedByCandidateFilter(const Candidate& c, uint32_t filter) {
return false;
}
- if (c.type() == RELAY_PORT_TYPE) {
+ if (c.is_relay()) {
return ((filter & CF_RELAY) != 0);
- } else if (c.type() == STUN_PORT_TYPE) {
+ }
+
+ if (c.is_stun()) {
return ((filter & CF_REFLEXIVE) != 0);
- } else if (c.type() == LOCAL_PORT_TYPE) {
+ }
+
+ if (c.is_local()) {
if ((filter & CF_REFLEXIVE) && !c.address().IsPrivateIP()) {
// We allow host candidates if the filter allows server-reflexive
// candidates and the candidate is a public IP. Because we don't generate
@@ -143,6 +147,7 @@ bool IsAllowedByCandidateFilter(const Candidate& c, uint32_t filter) {
return ((filter & CF_HOST) != 0);
}
+
return false;
}
@@ -199,21 +204,6 @@ BasicPortAllocator::BasicPortAllocator(
webrtc::NO_PRUNE, nullptr);
}
-void BasicPortAllocator::OnIceRegathering(PortAllocatorSession* session,
- IceRegatheringReason reason) {
- // If the session has not been taken by an active channel, do not report the
- // metric.
- for (auto& allocator_session : pooled_sessions()) {
- if (allocator_session.get() == session) {
- return;
- }
- }
-
- RTC_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.IceRegatheringReason",
- static_cast<int>(reason),
- static_cast<int>(IceRegatheringReason::MAX_VALUE));
-}
-
BasicPortAllocator::~BasicPortAllocator() {
CheckRunOnValidThreadIfInitialized();
// Our created port allocator sessions depend on us, so destroy our remaining
@@ -251,12 +241,9 @@ PortAllocatorSession* BasicPortAllocator::CreateSessionInternal(
absl::string_view ice_ufrag,
absl::string_view ice_pwd) {
CheckRunOnValidThreadAndInitialized();
- PortAllocatorSession* session = new BasicPortAllocatorSession(
- this, std::string(content_name), component, std::string(ice_ufrag),
- std::string(ice_pwd));
- session->SignalIceRegathering.connect(this,
- &BasicPortAllocator::OnIceRegathering);
- return session;
+ return new BasicPortAllocatorSession(this, std::string(content_name),
+ component, std::string(ice_ufrag),
+ std::string(ice_pwd));
}
void BasicPortAllocator::AddTurnServerForTesting(
diff --git a/third_party/libwebrtc/p2p/client/basic_port_allocator.h b/third_party/libwebrtc/p2p/client/basic_port_allocator.h
index 643904ab27..25201fd016 100644
--- a/third_party/libwebrtc/p2p/client/basic_port_allocator.h
+++ b/third_party/libwebrtc/p2p/client/basic_port_allocator.h
@@ -85,9 +85,6 @@ class RTC_EXPORT BasicPortAllocator : public PortAllocator {
}
private:
- void OnIceRegathering(PortAllocatorSession* session,
- IceRegatheringReason reason);
-
bool MdnsObfuscationEnabled() const override;
webrtc::AlwaysValidPointer<const webrtc::FieldTrialsView,
diff --git a/third_party/libwebrtc/p2p/client/basic_port_allocator_unittest.cc b/third_party/libwebrtc/p2p/client/basic_port_allocator_unittest.cc
index defcab01c9..0c3bf6bc23 100644
--- a/third_party/libwebrtc/p2p/client/basic_port_allocator_unittest.cc
+++ b/third_party/libwebrtc/p2p/client/basic_port_allocator_unittest.cc
@@ -496,8 +496,8 @@ class BasicPortAllocatorTestBase : public ::testing::Test,
bool with_nat) {
if (with_nat) {
nat_server_.reset(new rtc::NATServer(
- rtc::NAT_OPEN_CONE, vss_.get(), kNatUdpAddr, kNatTcpAddr, vss_.get(),
- rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)));
+ rtc::NAT_OPEN_CONE, thread_, vss_.get(), kNatUdpAddr, kNatTcpAddr,
+ thread_, vss_.get(), rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)));
} else {
nat_socket_factory_ =
std::make_unique<rtc::BasicPacketSocketFactory>(fss_.get());
@@ -2390,24 +2390,6 @@ TEST_F(BasicPortAllocatorTest,
expected_stun_keepalive_interval);
}
-TEST_F(BasicPortAllocatorTest, IceRegatheringMetricsLoggedWhenNetworkChanges) {
- // Only test local ports to simplify test.
- ResetWithNoServersOrNat();
- AddInterface(kClientAddr, "test_net0");
- ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
- session_->StartGettingPorts();
- EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
- kDefaultAllocationTimeout, fake_clock);
- candidate_allocation_done_ = false;
- AddInterface(kClientAddr2, "test_net1");
- EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
- kDefaultAllocationTimeout, fake_clock);
- EXPECT_METRIC_EQ(1,
- webrtc::metrics::NumEvents(
- "WebRTC.PeerConnection.IceRegatheringReason",
- static_cast<int>(IceRegatheringReason::NETWORK_CHANGE)));
-}
-
// Test that when an mDNS responder is present, the local address of a host
// candidate is concealed by an mDNS hostname and the related address of a srflx
// candidate is set to 0.0.0.0 or ::0.
@@ -2435,7 +2417,7 @@ TEST_F(BasicPortAllocatorTest, HostCandidateAddressIsReplacedByHostname) {
for (const auto& candidate : candidates_) {
const auto& raddr = candidate.related_address();
- if (candidate.type() == LOCAL_PORT_TYPE) {
+ if (candidate.is_local()) {
EXPECT_FALSE(candidate.address().hostname().empty());
EXPECT_TRUE(raddr.IsNil());
if (candidate.protocol() == UDP_PROTOCOL_NAME) {
@@ -2443,13 +2425,13 @@ TEST_F(BasicPortAllocatorTest, HostCandidateAddressIsReplacedByHostname) {
} else {
++num_host_tcp_candidates;
}
- } else if (candidate.type() == STUN_PORT_TYPE) {
+ } else if (candidate.is_stun()) {
// For a srflx candidate, the related address should be set to 0.0.0.0 or
// ::0
EXPECT_TRUE(IPIsAny(raddr.ipaddr()));
EXPECT_EQ(raddr.port(), 0);
++num_srflx_candidates;
- } else if (candidate.type() == RELAY_PORT_TYPE) {
+ } else if (candidate.is_relay()) {
EXPECT_EQ(kNatUdpAddr.ipaddr(), raddr.ipaddr());
EXPECT_EQ(kNatUdpAddr.family(), raddr.family());
++num_relay_candidates;
diff --git a/third_party/libwebrtc/p2p/stunprober/stun_prober.cc b/third_party/libwebrtc/p2p/stunprober/stun_prober.cc
index c60e7ede89..d130d780dc 100644
--- a/third_party/libwebrtc/p2p/stunprober/stun_prober.cc
+++ b/third_party/libwebrtc/p2p/stunprober/stun_prober.cc
@@ -156,8 +156,8 @@ void StunProber::Requester::SendStunRequest() {
// request timing could become too complicated. Callback is ignored by passing
// empty AsyncCallback.
rtc::PacketOptions options;
- int rv = socket_->SendTo(const_cast<char*>(request_packet->Data()),
- request_packet->Length(), addr, options);
+ int rv = socket_->SendTo(request_packet->Data(), request_packet->Length(),
+ addr, options);
if (rv < 0) {
prober_->ReportOnFinished(WRITE_FAILED);
return;