commit 1862abc0a5050a6fabd8a0b17745603c90876e9e
parent c5dcf78ffbd229e68515920a8a3627e3b2a9b8c9
Author: Dan Baker <dbaker@mozilla.com>
Date: Mon, 1 Dec 2025 17:32:29 -0700
Bug 2000941 - Vendor libwebrtc from 9cd5923be4
Upstream commit: https://webrtc.googlesource.com/src/+/9cd5923be41d5c518cbac3ecd8b06c1b2a837364
Create Environment in EmulatedNetworkManager test helper
This is a preparation for passing Environment into TurnServer where it
will be needed to create AsyncPacketSockets
Bug: webrtc:42223992
Change-Id: I83dddb2e20a6aab4b8ac25d08907343e561302be
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/408160
Reviewed-by: Jeremy Leconte <jleconte@google.com>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Evan Shrubsole <eshr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45585}
Diffstat:
8 files changed, 51 insertions(+), 36 deletions(-)
diff --git a/third_party/libwebrtc/README.mozilla.last-vendor b/third_party/libwebrtc/README.mozilla.last-vendor
@@ -1,4 +1,4 @@
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
-libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-02T00:29:31.104363+00:00.
+libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-02T00:32:13.161451+00:00.
# base of lastest vendoring
-edd4005f76
+9cd5923be4
diff --git a/third_party/libwebrtc/test/create_test_environment.cc b/third_party/libwebrtc/test/create_test_environment.cc
@@ -33,9 +33,12 @@ struct SetFieldTrials {
factory.Set(CreateTestFieldTrialsPtr(field_trials));
}
- void operator()(FieldTrialsView* absl_nonnull field_trials) {
- RTC_CHECK(field_trials != nullptr);
- factory.Set(field_trials);
+ void operator()(const FieldTrialsView* absl_nullable field_trials) {
+ if (field_trials != nullptr) {
+ factory.Set(field_trials);
+ } else {
+ factory.Set(CreateTestFieldTrialsPtr());
+ }
}
void operator()(absl_nonnull std::unique_ptr<FieldTrialsView> field_trials) {
diff --git a/third_party/libwebrtc/test/create_test_environment.h b/third_party/libwebrtc/test/create_test_environment.h
@@ -31,7 +31,7 @@ namespace webrtc {
// tests are refactored not to rely on it.
struct CreateTestEnvironmentOptions {
std::variant<absl::string_view,
- FieldTrialsView * absl_nonnull,
+ const FieldTrialsView * absl_nullable,
absl_nonnull std::unique_ptr<FieldTrialsView>,
FieldTrials>
field_trials;
diff --git a/third_party/libwebrtc/test/network/BUILD.gn b/third_party/libwebrtc/test/network/BUILD.gn
@@ -40,6 +40,7 @@ rtc_library("emulated_network") {
]
deps = [
":simulated_network",
+ "..:create_test_environment",
"../../api:array_view",
"../../api:async_dns_resolver",
"../../api:field_trials_view",
@@ -49,6 +50,7 @@ rtc_library("emulated_network") {
"../../api:sequence_checker",
"../../api:simulated_network_api",
"../../api:time_controller",
+ "../../api/environment",
"../../api/numerics",
"../../api/task_queue",
"../../api/task_queue:pending_task_safety_flag",
diff --git a/third_party/libwebrtc/test/network/emulated_turn_server.cc b/third_party/libwebrtc/test/network/emulated_turn_server.cc
@@ -17,6 +17,7 @@
#include <utility>
#include "api/async_dns_resolver.h"
+#include "api/environment/environment.h"
#include "api/packet_socket_factory.h"
#include "api/sequence_checker.h"
#include "api/test/network_emulation/network_emulation_interfaces.h"
@@ -52,7 +53,7 @@ class PacketSocketFactoryWrapper : public webrtc::PacketSocketFactory {
const webrtc::SocketAddress& address,
uint16_t min_port,
uint16_t max_port) override {
- return turn_server_->CreatePeerSocket();
+ return turn_server_->CreatePeerSocket().release();
}
webrtc::AsyncListenSocket* CreateServerTcpSocket(
@@ -131,27 +132,27 @@ class EmulatedTURNServer::AsyncPacketSocketWrapper : public AsyncPacketSocket {
const SocketAddress local_address_;
};
-EmulatedTURNServer::EmulatedTURNServer(const EmulatedTURNServerConfig& config,
+EmulatedTURNServer::EmulatedTURNServer(const Environment& env,
+ const EmulatedTURNServerConfig& config,
std::unique_ptr<Thread> thread,
EmulatedEndpoint* client,
EmulatedEndpoint* peer)
: thread_(std::move(thread)), client_(client), peer_(peer) {
ice_config_.username = "keso";
ice_config_.password = "keso";
- SendTask(thread_.get(), [this, enable_permission_checks =
- config.enable_permission_checks]() {
+ SendTask(thread_.get(), [&] {
RTC_DCHECK_RUN_ON(thread_.get());
turn_server_ = std::make_unique<TurnServer>(thread_.get());
turn_server_->set_realm(kTestRealm);
turn_server_->set_realm(kTestSoftware);
turn_server_->set_auth_hook(this);
- turn_server_->set_enable_permission_checks(enable_permission_checks);
+ turn_server_->set_enable_permission_checks(config.enable_permission_checks);
- auto client_socket = Wrap(client_);
- turn_server_->AddInternalSocket(client_socket, PROTO_UDP);
+ std::unique_ptr<AsyncPacketSocket> client_socket = Wrap(client_);
+ client_address_ = client_socket->GetLocalAddress();
+ turn_server_->AddInternalSocket(client_socket.release(), PROTO_UDP);
turn_server_->SetExternalSocketFactory(new PacketSocketFactoryWrapper(this),
SocketAddress());
- client_address_ = client_socket->GetLocalAddress();
char buf[256];
SimpleStringBuilder str(buf);
str.AppendFormat("turn:%s?transport=udp",
@@ -174,11 +175,13 @@ EmulatedTURNServer::~EmulatedTURNServer() {
});
}
-AsyncPacketSocket* EmulatedTURNServer::Wrap(EmulatedEndpoint* endpoint) {
+std::unique_ptr<AsyncPacketSocket> EmulatedTURNServer::Wrap(
+ EmulatedEndpoint* endpoint) {
RTC_DCHECK_RUN_ON(thread_.get());
auto port = endpoint->BindReceiver(0, this).value();
- auto socket = new AsyncPacketSocketWrapper(this, endpoint, port);
- sockets_[SocketAddress(endpoint->GetPeerLocalAddress(), port)] = socket;
+ auto socket =
+ std::make_unique<AsyncPacketSocketWrapper>(this, endpoint, port);
+ sockets_[SocketAddress(endpoint->GetPeerLocalAddress(), port)] = socket.get();
return socket;
}
diff --git a/third_party/libwebrtc/test/network/emulated_turn_server.h b/third_party/libwebrtc/test/network/emulated_turn_server.h
@@ -16,6 +16,7 @@
#include <string>
#include "absl/strings/string_view.h"
+#include "api/environment/environment.h"
#include "api/test/network_emulation/network_emulation_interfaces.h"
#include "api/test/network_emulation_manager.h"
#include "api/transport/stun.h"
@@ -46,7 +47,8 @@ class EmulatedTURNServer : public EmulatedTURNServerInterface,
// Create an EmulatedTURNServer.
// `thread` is a thread that will be used to run webrtc::TurnServer
// that expects all calls to be made from a single thread.
- EmulatedTURNServer(const EmulatedTURNServerConfig& config,
+ EmulatedTURNServer(const Environment& env,
+ const EmulatedTURNServerConfig& config,
std::unique_ptr<Thread> thread,
EmulatedEndpoint* client,
EmulatedEndpoint* peer);
@@ -70,7 +72,7 @@ class EmulatedTURNServer : public EmulatedTURNServerInterface,
std::string(username), key);
}
- AsyncPacketSocket* CreatePeerSocket() { return Wrap(peer_); }
+ std::unique_ptr<AsyncPacketSocket> CreatePeerSocket() { return Wrap(peer_); }
// This method is called by network emulation when a packet
// comes from an emulated link.
@@ -94,8 +96,8 @@ class EmulatedTURNServer : public EmulatedTURNServerInterface,
RTC_GUARDED_BY(&thread_);
// Wraps a EmulatedEndpoint in a AsyncPacketSocket to bridge interaction
- // with TurnServer. webrtc::TurnServer gets ownership of the socket.
- AsyncPacketSocket* Wrap(EmulatedEndpoint* endpoint);
+ // with TurnServer.
+ std::unique_ptr<AsyncPacketSocket> Wrap(EmulatedEndpoint* endpoint);
};
} // namespace test
diff --git a/third_party/libwebrtc/test/network/network_emulation_manager.cc b/third_party/libwebrtc/test/network/network_emulation_manager.cc
@@ -34,6 +34,7 @@
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/task_queue_for_test.h"
#include "rtc_base/task_utils/repeating_task.h"
+#include "test/create_test_environment.h"
#include "test/network/cross_traffic.h"
#include "test/network/emulated_network_manager.h"
#include "test/network/emulated_turn_server.h"
@@ -74,11 +75,12 @@ NetworkEmulationManagerImpl::NetworkEmulationManagerImpl(
stats_gathering_mode_(config.stats_gathering_mode),
time_controller_(
CreateTimeController(config.time_mode, config.field_trials)),
- clock_(time_controller_->GetClock()),
+ env_(CreateTestEnvironment({.field_trials = config.field_trials,
+ .time = time_controller_.get()})),
fake_dtls_handshake_sizes_(config.fake_dtls_handshake_sizes),
next_node_id_(1),
next_ip4_address_(kMinIPv4Address),
- task_queue_(time_controller_->GetTaskQueueFactory()->CreateTaskQueue(
+ task_queue_(env_.task_queue_factory().CreateTaskQueue(
"NetworkEmulation",
TaskQueueFactory::Priority::NORMAL)) {}
@@ -101,7 +103,7 @@ EmulatedNetworkNode* NetworkEmulationManagerImpl::CreateEmulatedNode(
EmulatedNetworkNode* NetworkEmulationManagerImpl::CreateEmulatedNode(
std::unique_ptr<NetworkBehaviorInterface> network_behavior) {
auto node = std::make_unique<EmulatedNetworkNode>(
- clock_, task_queue_.Get(), std::move(network_behavior),
+ &env_.clock(), task_queue_.Get(), std::move(network_behavior),
stats_gathering_mode_, fake_dtls_handshake_sizes_);
EmulatedNetworkNode* out = node.get();
task_queue_.PostTask([this, node = std::move(node)]() mutable {
@@ -137,7 +139,7 @@ EmulatedEndpointImpl* NetworkEmulationManagerImpl::CreateEndpoint(
auto node = std::make_unique<EmulatedEndpointImpl>(
EmulatedEndpointImpl::Options(next_node_id_++, *ip, config,
stats_gathering_mode_),
- config.start_as_enabled, task_queue_.Get(), clock_);
+ config.start_as_enabled, task_queue_.Get(), &env_.clock());
EmulatedEndpointImpl* out = node.get();
endpoints_.push_back(std::move(node));
return out;
@@ -242,7 +244,7 @@ TcpMessageRoute* NetworkEmulationManagerImpl::CreateTcpRoute(
EmulatedRoute* send_route,
EmulatedRoute* ret_route) {
auto tcp_route = std::make_unique<TcpMessageRouteImpl>(
- clock_, task_queue_.Get(), send_route, ret_route);
+ &env_.clock(), task_queue_.Get(), send_route, ret_route);
auto* route_ptr = tcp_route.get();
task_queue_.PostTask([this, tcp_route = std::move(tcp_route)]() mutable {
tcp_message_routes_.push_back(std::move(tcp_route));
@@ -265,7 +267,8 @@ CrossTrafficRoute* NetworkEmulationManagerImpl::CreateCrossTrafficRoute(
cur_node->router()->SetReceiver(endpoint->GetPeerLocalAddress(), endpoint);
std::unique_ptr<CrossTrafficRoute> traffic_route =
- std::make_unique<CrossTrafficRouteImpl>(clock_, via_nodes[0], endpoint);
+ std::make_unique<CrossTrafficRouteImpl>(&env_.clock(), via_nodes[0],
+ endpoint);
CrossTrafficRoute* out = traffic_route.get();
traffic_routes_.push_back(std::move(traffic_route));
return out;
@@ -310,7 +313,7 @@ NetworkEmulationManagerImpl::CreateEmulatedNetworkManagerInterface(
endpoint_impls.push_back(static_cast<EmulatedEndpointImpl*>(endpoint));
}
auto endpoints_container = std::make_unique<EndpointsContainer>(
- clock_, endpoint_impls, stats_gathering_mode_);
+ &env_.clock(), endpoint_impls, stats_gathering_mode_);
auto network_manager = std::make_unique<EmulatedNetworkManager>(
time_controller_.get(), task_queue_.Get(), endpoints_container.get());
for (auto* endpoint : endpoints) {
@@ -328,9 +331,10 @@ NetworkEmulationManagerImpl::CreateEmulatedNetworkManagerInterface(
void NetworkEmulationManagerImpl::GetStats(
ArrayView<EmulatedEndpoint* const> endpoints,
std::function<void(EmulatedNetworkStats)> stats_callback) {
- task_queue_.PostTask([endpoints, stats_callback, clock = clock_,
+ task_queue_.PostTask([endpoints, stats_callback, env = env_,
stats_gathering_mode = stats_gathering_mode_]() {
- EmulatedNetworkStatsBuilder stats_builder(*clock, stats_gathering_mode);
+ EmulatedNetworkStatsBuilder stats_builder(env.clock(),
+ stats_gathering_mode);
for (auto* endpoint : endpoints) {
// It's safe to cast here because EmulatedEndpointImpl can be the only
// implementation of EmulatedEndpoint, because only it has access to
@@ -345,9 +349,10 @@ void NetworkEmulationManagerImpl::GetStats(
void NetworkEmulationManagerImpl::GetStats(
ArrayView<EmulatedNetworkNode* const> nodes,
std::function<void(EmulatedNetworkNodeStats)> stats_callback) {
- task_queue_.PostTask([nodes, stats_callback, clock = clock_,
+ task_queue_.PostTask([nodes, stats_callback, env = env_,
stats_gathering_mode = stats_gathering_mode_]() {
- EmulatedNetworkNodeStatsBuilder stats_builder(*clock, stats_gathering_mode);
+ EmulatedNetworkNodeStatsBuilder stats_builder(env.clock(),
+ stats_gathering_mode);
for (auto* node : nodes) {
stats_builder.AddEmulatedNetworkNodeStats(node->stats());
}
@@ -372,7 +377,7 @@ std::optional<IPAddress> NetworkEmulationManagerImpl::GetNextIPv4Address() {
}
Timestamp NetworkEmulationManagerImpl::Now() const {
- return clock_->CurrentTime();
+ return env_.clock().CurrentTime();
}
EmulatedTURNServerInterface* NetworkEmulationManagerImpl::CreateTURNServer(
@@ -384,7 +389,7 @@ EmulatedTURNServerInterface* NetworkEmulationManagerImpl::CreateTURNServer(
str.AppendFormat("turn_server_%u",
static_cast<unsigned>(turn_servers_.size()));
auto turn = std::make_unique<EmulatedTURNServer>(
- config, time_controller_->CreateThread(str.str()), client, peer);
+ env_, config, time_controller_->CreateThread(str.str()), client, peer);
auto out = turn.get();
turn_servers_.push_back(std::move(turn));
return out;
diff --git a/third_party/libwebrtc/test/network/network_emulation_manager.h b/third_party/libwebrtc/test/network/network_emulation_manager.h
@@ -23,6 +23,7 @@
#include "absl/base/nullability.h"
#include "api/array_view.h"
+#include "api/environment/environment.h"
#include "api/test/network_emulation/cross_traffic.h"
#include "api/test/network_emulation/network_emulation_interfaces.h"
#include "api/test/network_emulation_manager.h"
@@ -32,7 +33,6 @@
#include "rtc_base/ip_address.h"
#include "rtc_base/task_queue_for_test.h"
#include "rtc_base/task_utils/repeating_task.h"
-#include "system_wrappers/include/clock.h"
#include "test/network/cross_traffic.h"
#include "test/network/emulated_network_manager.h"
#include "test/network/emulated_turn_server.h"
@@ -111,7 +111,7 @@ class NetworkEmulationManagerImpl : public NetworkEmulationManager {
const TimeMode time_mode_;
const EmulatedNetworkStatsGatheringMode stats_gathering_mode_;
const std::unique_ptr<TimeController> time_controller_;
- Clock* const clock_;
+ const Environment env_;
const bool fake_dtls_handshake_sizes_;
int next_node_id_;