diff --git a/Package.swift b/Package.swift index c1479440..c110301e 100644 --- a/Package.swift +++ b/Package.swift @@ -410,6 +410,7 @@ let package = Package( "internal/BUILD", "internal/crypto/BUILD", "internal/crypto/BUILD.gn", + "internal/platform/flags/BUILD", "internal/platform/implementation/shared/BUILD", "internal/platform/implementation/apple/Mediums/BUILD", "internal/platform/implementation/apple/Mediums/Ble/Sockets/BUILD", diff --git a/internal/platform/feature_flags.h b/internal/platform/feature_flags.h index 14e42267..9aae0f39 100644 --- a/internal/platform/feature_flags.h +++ b/internal/platform/feature_flags.h @@ -53,11 +53,6 @@ class FeatureFlags { // Controls to enable or disable to track the status of Bluetooth classic // conncetion. bool enable_bluetooth_connection_status_track = true; - // If Hotspot or WFD GO use WinRT API to create the server socket, the - // StreamSocketListener::BindEndpointAsync() will takes about 11s, so we - // prefer to use legacy WinSock API to create the server socket and do the - // binding, which only takes less than 0.1s - bool use_winsock = true; }; static const FeatureFlags& GetInstance() { diff --git a/internal/platform/flags/BUILD b/internal/platform/flags/BUILD new file mode 100644 index 00000000..15f5cf6f --- /dev/null +++ b/internal/platform/flags/BUILD @@ -0,0 +1,29 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +licenses(["notice"]) + +cc_library( + name = "platform_flags", + hdrs = [ + "nearby_platform_feature_flags.h", + ], + visibility = [ + "//internal:__subpackages__", + "//location/nearby/cpp:__subpackages__", + ], + deps = [ + "//internal/flags:flag_reader", + "@com_google_absl//absl/strings", + ], +) diff --git a/internal/platform/flags/nearby_platform_feature_flags.h b/internal/platform/flags/nearby_platform_feature_flags.h new file mode 100644 index 00000000..ff899639 --- /dev/null +++ b/internal/platform/flags/nearby_platform_feature_flags.h @@ -0,0 +1,39 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_FLAGS_NEARBY_PLATFORM_FEATURE_FLAGS_H_ +#define THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_FLAGS_NEARBY_PLATFORM_FEATURE_FLAGS_H_ + +#include "absl/strings/string_view.h" +#include "internal/flags/flag.h" + +namespace nearby { +namespace platform { +namespace config_package_nearby { + +constexpr absl::string_view kConfigPackage = "nearby"; + +// The Nearby Platform features. +namespace nearby_platform_feature { + +// Disable/Enable win32 socket implementation for Wi-Fi hotspot. +constexpr auto kEnableHotspotWin32Socket = + flags::Flag(kConfigPackage, "45401992", true); + +} // namespace nearby_platform_feature +} // namespace config_package_nearby +} // namespace platform +} // namespace nearby + +#endif // THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_FLAGS_NEARBY_PLATFORM_FEATURE_FLAGS_H_ diff --git a/internal/platform/implementation/windows/BUILD b/internal/platform/implementation/windows/BUILD index d89f360d..086b3c07 100644 --- a/internal/platform/implementation/windows/BUILD +++ b/internal/platform/implementation/windows/BUILD @@ -184,12 +184,14 @@ cc_library( ":comm", ":crypto", # build_cleaner: keep ":types", + "//internal/flags:nearby_flags", "//internal/platform:base", "//internal/platform:cancellation_flag", "//internal/platform:comm", "//internal/platform:logging", "//internal/platform:types", "//internal/platform:uuid", + "//internal/platform/flags:platform_flags", "//internal/platform/implementation:comm", "//internal/platform/implementation:platform", "//internal/platform/implementation:types", diff --git a/internal/platform/implementation/windows/wifi_hotspot_server_socket.cc b/internal/platform/implementation/windows/wifi_hotspot_server_socket.cc index a1933ffa..3b742a2f 100644 --- a/internal/platform/implementation/windows/wifi_hotspot_server_socket.cc +++ b/internal/platform/implementation/windows/wifi_hotspot_server_socket.cc @@ -23,7 +23,8 @@ #include "absl/strings/match.h" // Nearby connections headers -#include "internal/platform/feature_flags.h" +#include "internal/flags/nearby_flags.h" +#include "internal/platform/flags/nearby_platform_feature_flags.h" #include "internal/platform/implementation/windows/generated/winrt/Windows.Networking.Sockets.h" #include "internal/platform/implementation/windows/utils.h" #include "internal/platform/implementation/windows/wifi_hotspot.h" @@ -43,7 +44,9 @@ WifiHotspotServerSocket::WifiHotspotServerSocket(int port) : port_(port) {} WifiHotspotServerSocket::~WifiHotspotServerSocket() { Close(); } std::string WifiHotspotServerSocket::GetIPAddress() const { - if (FeatureFlags::GetInstance().GetFlags().use_winsock) { + if (NearbyFlags::GetInstance().GetBoolFlag( + platform::config_package_nearby::nearby_platform_feature:: + kEnableHotspotWin32Socket)) { if (listen_socket_ == INVALID_SOCKET) { return {}; } @@ -64,7 +67,9 @@ std::string WifiHotspotServerSocket::GetIPAddress() const { } int WifiHotspotServerSocket::GetPort() const { - if (FeatureFlags::GetInstance().GetFlags().use_winsock) { + if (NearbyFlags::GetInstance().GetBoolFlag( + platform::config_package_nearby::nearby_platform_feature:: + kEnableHotspotWin32Socket)) { if (listen_socket_ == INVALID_SOCKET) { NEARBY_LOGS(WARNING) << __func__ << ": listen_socket_ is invalid."; return 0; @@ -82,7 +87,9 @@ std::unique_ptr WifiHotspotServerSocket::Accept() { absl::MutexLock lock(&mutex_); NEARBY_LOGS(INFO) << __func__ << ": Accept is called."; - if (FeatureFlags::GetInstance().GetFlags().use_winsock) { + if (NearbyFlags::GetInstance().GetBoolFlag( + platform::config_package_nearby::nearby_platform_feature:: + kEnableHotspotWin32Socket)) { while (!closed_ && pending_client_sockets_.empty()) { cond_.Wait(&mutex_); } @@ -116,7 +123,9 @@ Exception WifiHotspotServerSocket::Close() { absl::MutexLock lock(&mutex_); NEARBY_LOGS(INFO) << __func__ << ": Close is called."; - if (FeatureFlags::GetInstance().GetFlags().use_winsock) { + if (NearbyFlags::GetInstance().GetBoolFlag( + platform::config_package_nearby::nearby_platform_feature:: + kEnableHotspotWin32Socket)) { if (listen_socket_ != INVALID_SOCKET) { NEARBY_LOGS(INFO) << ": Close listen_socket_: " << listen_socket_; closesocket(listen_socket_); @@ -399,7 +408,9 @@ bool WifiHotspotServerSocket::listen() { return false; } - if (FeatureFlags::GetInstance().GetFlags().use_winsock) { + if (NearbyFlags::GetInstance().GetBoolFlag( + platform::config_package_nearby::nearby_platform_feature:: + kEnableHotspotWin32Socket)) { return SetupServerSocketWinSock(); } else { return SetupServerSocketWinRT();