internal cleanup

PiperOrigin-RevId: 517211099
This commit is contained in:
Guogang Li
2023-03-16 13:27:26 -07:00
committed by Copybara-Service
parent 3f61031345
commit f7e6deb8ab
6 changed files with 88 additions and 11 deletions
+1
View File
@@ -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",
-5
View File
@@ -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() {
+29
View File
@@ -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",
],
)
@@ -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<bool>(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_
@@ -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",
@@ -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<api::WifiHotspotSocket> 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();