diff --git a/engine/src/flutter/common/settings.h b/engine/src/flutter/common/settings.h index 201fdb8acc2..690abce3f82 100644 --- a/engine/src/flutter/common/settings.h +++ b/engine/src/flutter/common/settings.h @@ -19,6 +19,7 @@ struct Settings { uint32_t observatory_port = 0; bool enable_diagnostic = false; uint32_t diagnostic_port = 0; + bool ipv6 = false; bool start_paused = false; bool trace_startup = false; bool endless_trace_buffer = false; diff --git a/engine/src/flutter/runtime/dart_init.cc b/engine/src/flutter/runtime/dart_init.cc index abbb113cf9e..b132e1fd09b 100644 --- a/engine/src/flutter/runtime/dart_init.cc +++ b/engine/src/flutter/runtime/dart_init.cc @@ -196,7 +196,7 @@ Dart_Isolate ServiceIsolateCreateCallback(const char* script_uri, DartRuntimeHooks::Install(DartRuntimeHooks::SecondaryIsolate, script_uri); const Settings& settings = Settings::Get(); if (settings.enable_observatory) { - std::string ip = "127.0.0.1"; + std::string ip = settings.ipv6 ? "::1" : "127.0.0.1"; const intptr_t port = settings.observatory_port; const bool disable_websocket_origin_check = false; const bool service_isolate_booted = DartServiceIsolate::Startup( diff --git a/engine/src/flutter/shell/common/diagnostic/diagnostic_server.cc b/engine/src/flutter/shell/common/diagnostic/diagnostic_server.cc index fb0483999a3..2730dfd732a 100644 --- a/engine/src/flutter/shell/common/diagnostic/diagnostic_server.cc +++ b/engine/src/flutter/shell/common/diagnostic/diagnostic_server.cc @@ -61,7 +61,7 @@ void SendNull(Dart_Port port_id) { DART_NATIVE_CALLBACK_STATIC(DiagnosticServer, HandleSkiaPictureRequest); -void DiagnosticServer::Start(uint32_t port) { +void DiagnosticServer::Start(uint32_t port, bool ipv6) { if (!g_natives) { g_natives = new DartLibraryNatives(); g_natives->Register({ @@ -92,7 +92,8 @@ void DiagnosticServer::Start(uint32_t port) { FTL_CHECK(!LogIfError(Dart_FinalizeLoading(false))); - DartInvokeField(Dart_RootLibrary(), "diagnosticServerStart", {ToDart(port)}); + DartInvokeField(Dart_RootLibrary(), "diagnosticServerStart", + {ToDart(port), ToDart(ipv6)}); } void DiagnosticServer::HandleSkiaPictureRequest(Dart_Handle send_port) { diff --git a/engine/src/flutter/shell/common/diagnostic/diagnostic_server.dart b/engine/src/flutter/shell/common/diagnostic/diagnostic_server.dart index aea869239fd..4b13f4e8b19 100644 --- a/engine/src/flutter/shell/common/diagnostic/diagnostic_server.dart +++ b/engine/src/flutter/shell/common/diagnostic/diagnostic_server.dart @@ -11,13 +11,17 @@ import 'dart:typed_data'; void handleSkiaPictureRequest(SendPort sendPort) native 'DiagnosticServer_HandleSkiaPictureRequest'; -void diagnosticServerStart(int port) { - HttpServer.bind('127.0.0.1', port).then((HttpServer server) { +void diagnosticServerStart(int port, [bool ipv6 = false]) { + InternetAddress address = ipv6 + ? InternetAddress.LOOPBACK_IP_V6 + : InternetAddress.LOOPBACK_IP_V4; + HttpServer.bind(address, port).then((HttpServer server) { server.listen(dispatchRequest, cancelOnError: true); - String ip = server.address.address.toString(); + String ip = address.address; String port = server.port.toString(); - print('Diagnostic server listening on http://$ip:$port/'); + String url = ipv6 ? 'http://[$ip]:$port/' : 'http://$ip:$port/'; + print('Diagnostic server listening on $url'); }); } diff --git a/engine/src/flutter/shell/common/diagnostic/diagnostic_server.h b/engine/src/flutter/shell/common/diagnostic/diagnostic_server.h index b5f9e1d00bb..bd9503abf3c 100644 --- a/engine/src/flutter/shell/common/diagnostic/diagnostic_server.h +++ b/engine/src/flutter/shell/common/diagnostic/diagnostic_server.h @@ -11,7 +11,7 @@ namespace shell { class DiagnosticServer { public: - static void Start(uint32_t port); + static void Start(uint32_t port, bool ipv6); static void HandleSkiaPictureRequest(Dart_Handle send_port); private: diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index 5ca5e85e359..7899745ca83 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -61,7 +61,7 @@ void ServiceIsolateHook(bool running_precompiled) { if (!running_precompiled) { const blink::Settings& settings = blink::Settings::Get(); if (settings.enable_diagnostic) - DiagnosticServer::Start(settings.diagnostic_port); + DiagnosticServer::Start(settings.diagnostic_port, settings.ipv6); } } @@ -136,6 +136,9 @@ void Shell::InitStandalone(ftl::CommandLine command_line, } } + settings.ipv6 = + command_line.HasOption(FlagForSwitch(Switch::IPv6)); + settings.start_paused = command_line.HasOption(FlagForSwitch(Switch::StartPaused)); diff --git a/engine/src/flutter/shell/common/switches.h b/engine/src/flutter/shell/common/switches.h index 4ced30821c8..d4d76b181ac 100644 --- a/engine/src/flutter/shell/common/switches.h +++ b/engine/src/flutter/shell/common/switches.h @@ -44,6 +44,10 @@ DEF_SWITCH(DisableDiagnostic, "disable-diagnostic", "Disable the diagnostic server. The diagnostic server is never " "available in release mode.") +DEF_SWITCH(IPv6, + "ipv6", + "Bind to the IPv6 localhost address for the Dart Observatory and " + "the diagnostic server.") DEF_SWITCH(EnableDartProfiling, "enable-dart-profiling", "Enable Dart profiling. Profiling information can be viewed from "