Add flag to control sending address candidates in WifiLan upgrade message.

PiperOrigin-RevId: 831563192
This commit is contained in:
Francis Tsui
2025-11-12 15:29:37 -08:00
committed by Copybara-Service
parent 4333bed749
commit fcee77457f
4 changed files with 48 additions and 21 deletions
+16 -14
View File
@@ -19,7 +19,6 @@
#include <utility>
#include <vector>
#include "absl/strings/str_cat.h"
#include "connections/connection_options.h"
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "connections/implementation/internal_payload.h"
@@ -30,6 +29,7 @@
#include "internal/flags/nearby_flags.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/exception.h"
#include "internal/platform/implementation/wifi_utils.h"
#include "internal/platform/logging.h"
#include "internal/platform/mac_address.h"
@@ -283,16 +283,6 @@ ByteArray ForBwuWifiHotspotPathAvailable(
ByteArray ForBwuWifiLanPathAvailable(
const std::vector<std::string>& ip_addresses, std::int32_t port) {
// For compatibility with Android versions, only use IPv4 address.
// IPv4 addresses are always at the end of the list.
std::string ip_address = ip_addresses.back();
if (ip_address.size() != 4) {
return {};
}
VLOG(1) << "WifiLanBwuPath retrieved WIFI_LAN credentials. IP addr: "
<< absl::Hex(ip_address[0]) << "." << absl::Hex(ip_address[1]) << "."
<< absl::Hex(ip_address[2]) << "." << absl::Hex(ip_address[3])
<< ", Port: " << port;
OfflineFrame frame;
frame.set_version(OfflineFrame::V1);
@@ -305,9 +295,21 @@ ByteArray ForBwuWifiLanPathAvailable(
upgrade_path_info->set_medium(UpgradePathInfo::WIFI_LAN);
upgrade_path_info->set_supports_client_introduction_ack(true);
auto* wifi_lan_socket = upgrade_path_info->mutable_wifi_lan_socket();
wifi_lan_socket->set_ip_address(ip_address);
wifi_lan_socket->set_wifi_port(port);
// For compatibility with Android versions, only use IPv4 address.
// IPv4 addresses are always at the end of the list.
std::string ip_address = ip_addresses.back();
if (ip_address.size() == 4) {
wifi_lan_socket->set_ip_address(ip_address);
wifi_lan_socket->set_wifi_port(port);
}
for (const auto& address : ip_addresses) {
auto* address_candidate = wifi_lan_socket->add_address_candidates();
std::string ip_address = std::string(address.begin(), address.end());
address_candidate->set_ip_address(ip_address);
address_candidate->set_port(port);
VLOG(1) << "ForBwuWifiLanPathAvailable: "
<< WifiUtils::GetHumanReadableIpAddress(ip_address) << ":" << port;
}
return ToBytes(std::move(frame));
}
@@ -441,12 +441,28 @@ TEST(OfflineFramesTest, CanGenerateBwuWifiLanPathAvailable) {
event_type: UPGRADE_PATH_AVAILABLE
upgrade_path_info: <
medium: WIFI_LAN
wifi_lan_socket: < ip_address: "\x01\x02\x03\x04" wifi_port: 1234 >
wifi_lan_socket: <
ip_address: "\x01\x02\x03\x04"
wifi_port: 1234
address_candidates: <
ip_address: "\x2a\x00\x79\xe0\x2e\x87\x00\x06\xb7\x28\x67\x45\x7a\xdd\x01\x53"
port: 1234
>
address_candidates: <
ip_address: "\001\002\003\004"
port: 1234
>
>
supports_client_introduction_ack: true
>
>
>)pb";
ByteArray bytes = ForBwuWifiLanPathAvailable({"\x01\x02\x03\x04"}, 1234);
ByteArray bytes = ForBwuWifiLanPathAvailable(
{std::string(
"\x2a\x00\x79\xe0\x2e\x87\x00\x06\xb7\x28\x67\x45\x7a\xdd\x01\x53",
16),
"\x01\x02\x03\x04"},
1234);
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = response.result();
@@ -73,10 +73,14 @@ constexpr auto kEnableIpv6DualStack =
constexpr auto kEnableMdnsIpv6 =
flags::Flag<bool>(kConfigPackage, "45735181", false);
// Enable/Disable new Bluetooth refactor
// Enable/Disable new Bluetooth refactor
constexpr auto kEnableNewBluetoothRefactor =
flags::Flag<bool>(kConfigPackage, "45615156", false);
// Enable/Disable use of address candidates for WifiLan upgrade in Windows.
constexpr auto kEnableWifiLanAddressCandidates =
flags::Flag<bool>(kConfigPackage, "45739995", false);
// The send buffer size of blocking socket
constexpr auto kSocketSendBufferSize =
flags::Flag<int64_t>(kConfigPackage, "45673785", 524288);
@@ -765,10 +765,15 @@ std::vector<std::string> WifiLanMedium::GetUpgradeAddressCandidates(
4));
}
}
// Append v4 addresses to the end of the list.
ip_addresses.insert(ip_addresses.end(), ipv4_addresses.begin(),
ipv4_addresses.end());
return ip_addresses;
if (NearbyFlags::GetInstance().GetBoolFlag(
platform::config_package_nearby::nearby_platform_feature::
kEnableWifiLanAddressCandidates)) {
// Append v4 addresses to the end of the list.
ip_addresses.insert(ip_addresses.end(), ipv4_addresses.begin(),
ipv4_addresses.end());
return ip_addresses;
}
return { ip_addresses.back() };
}
} // namespace nearby::windows