WifiLan::Change GetUpgradeAddressCandidates to use ServiceAddress.

PiperOrigin-RevId: 842257461
This commit is contained in:
Francis Tsui
2025-12-09 08:48:31 -08:00
committed by Copybara-Service
parent 8e597c9df0
commit 4652aef48c
22 changed files with 121 additions and 82 deletions
@@ -81,6 +81,7 @@
#include "internal/platform/prng.h"
#include "internal/platform/runnable.h"
#include "internal/platform/wifi.h"
#include "internal/platform/wifi_credential.h"
#include "internal/platform/wifi_lan_connection_info.h"
#include "proto/connections_enums.pb.h"
@@ -196,22 +197,21 @@ std::vector<ConnectionInfoVariant> BasePcpHandler::GetConnectionInfoFromResult(
BleConnectionInfo info("", "", "", {});
connection_infos.push_back(info);
} else if (medium == location::nearby::proto::connections::WIFI_LAN) {
std::pair<std::vector<std::string>, int> upgrade_candidates =
std::vector<ServiceAddress> upgrade_candidates =
mediums_->GetWifiLan().GetUpgradeAddressCandidates(
std::string(service_id));
const std::vector<std::string>& ip_addresses = upgrade_candidates.first;
std::string ip_address;
// Only use IPv4 address. IPv4 addresses are always at the end of the
// list.
if (!ip_addresses.empty()) {
ip_address = ip_addresses.back();
if (ip_address.size() != 4) {
ip_address.clear();
std::vector<char> ip_address;
int port = 0;
if (!upgrade_candidates.empty()) {
ip_address = upgrade_candidates.back().address;
if (ip_address.size() == 4) {
port = upgrade_candidates.back().port;
}
}
int port = upgrade_candidates.second;
WifiLanConnectionInfo info(
ip_address,
std::string(ip_address.begin(), ip_address.end()),
absl::StrCat(absl::Hex(port, absl::kZeroPad16)), "",
{});
connection_infos.push_back(info);
@@ -40,6 +40,7 @@
#include "internal/platform/count_down_latch.h"
#include "internal/platform/exception.h"
#include "internal/platform/feature_flags.h"
#include "internal/platform/wifi_credential.h"
#include "internal/proto/analytics/connections_log.pb.h"
#include "proto/connections_enums.pb.h"
@@ -984,9 +985,9 @@ TEST_F(BwuManagerTest, InitiateBwu_Revert_OnDisconnect_Wlan) {
CreateInitialEndpoint(&client_, kServiceIdA, kEndpointId1, Medium::BLUETOOTH);
ExceptionOr<OfflineFrame> wlan_path_available_frame = parser::FromBytes(
parser::ForBwuWifiLanPathAvailable(/*ip_addresses=*/{"ABCD"},
/*port=*/1234));
ExceptionOr<OfflineFrame> wlan_path_available_frame =
parser::FromBytes(parser::ForBwuWifiLanPathAvailable(
{ServiceAddress{.address = {'A', 'B', 'C', 'D'}, .port = 1234}}));
OfflineFrame frame = wlan_path_available_frame.result();
frame.set_version(OfflineFrame::V1);
auto* v1_frame = frame.mutable_v1();
@@ -34,6 +34,7 @@
#include "internal/platform/expected.h"
#include "internal/platform/logging.h"
#include "internal/platform/mac_address.h"
#include "internal/platform/wifi_credential.h"
namespace nearby {
namespace connections {
@@ -147,8 +148,8 @@ class FakeBwuHandler : public BaseBwuHandler {
/*mac_address=*/mac_address);
}
case location::nearby::proto::connections::WIFI_LAN:
return parser::ForBwuWifiLanPathAvailable(/*ip_addresses=*/{"ABCD"},
/*port=*/1234);
return parser::ForBwuWifiLanPathAvailable(
{ServiceAddress{.address = {'A', 'B', 'C', 'D'}, .port = 1234}});
case location::nearby::proto::connections::WEB_RTC:
case location::nearby::proto::connections::WEB_RTC_NON_CELLULAR:
return parser::ForBwuWebrtcPathAvailable(
@@ -36,6 +36,7 @@
#include "internal/platform/nsd_service_info.h"
#include "internal/platform/socket.h"
#include "internal/platform/types.h"
#include "internal/platform/wifi_credential.h"
#include "internal/platform/wifi_lan.h"
namespace nearby {
@@ -607,15 +608,14 @@ ExceptionOr<WifiLanSocket> WifiLan::CreateOutgoingMultiplexSocketLocked(
return ExceptionOr<WifiLanSocket>(Exception::kFailed);
}
std::pair<std::vector<std::string>, int> WifiLan::GetUpgradeAddressCandidates(
std::vector<ServiceAddress> WifiLan::GetUpgradeAddressCandidates(
const std::string& service_id) {
MutexLock lock(&mutex_);
const auto& it = server_sockets_.find(service_id);
if (it == server_sockets_.end()) {
return std::pair<std::vector<std::string>, int>();
return {};
}
return {medium_.GetUpgradeAddressCandidates(it->second),
it->second.GetPort()};
return medium_.GetUpgradeAddressCandidates(it->second);
}
std::string WifiLan::GenerateServiceType(const std::string& service_id) {
@@ -33,6 +33,7 @@
#include "internal/platform/multi_thread_executor.h"
#include "internal/platform/mutex.h"
#include "internal/platform/nsd_service_info.h"
#include "internal/platform/wifi_credential.h"
#include "internal/platform/wifi_lan.h"
namespace nearby {
@@ -116,7 +117,7 @@ class WifiLan {
// The candidates list is ordered to have IPv6 addresses first, then IPv4.
// Both IPv4 and IPv6 adddresses are represented as network order byte
// sequence.
std::pair<std::vector<std::string>, int> GetUpgradeAddressCandidates(
std::vector<ServiceAddress> GetUpgradeAddressCandidates(
const std::string& service_id) ABSL_LOCKS_EXCLUDED(mutex_);
private:
@@ -16,6 +16,7 @@
#include <string>
#include <utility>
#include <vector>
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
@@ -31,6 +32,7 @@
#include "internal/platform/medium_environment.h"
#include "internal/platform/nsd_service_info.h"
#include "internal/platform/single_thread_executor.h"
#include "internal/platform/wifi_credential.h"
#include "internal/platform/wifi_lan.h"
namespace nearby {
@@ -73,15 +75,15 @@ TEST_P(WifiLanTest, AdvertiseSameServiceNameReusesPort) {
NsdServiceInfo nsd_service_info;
nsd_service_info.SetServiceName(std::string(kServiceInfoName));
wifi_lan_server.StartAdvertising(service_id, nsd_service_info, {});
auto [addresses, port] =
std::vector<ServiceAddress> addresses =
wifi_lan_server.GetUpgradeAddressCandidates(service_id);
wifi_lan_server.StopAdvertising(service_id);
wifi_lan_server.StopAcceptingConnections(service_id);
wifi_lan_server.StartAdvertising(service_id, nsd_service_info, {});
auto [addresses2, port2] =
std::vector<ServiceAddress> addresses2 =
wifi_lan_server.GetUpgradeAddressCandidates(service_id);
EXPECT_EQ(port, port2);
EXPECT_EQ(addresses.back().port, addresses2.back().port);
env_.Stop();
}
@@ -97,16 +99,16 @@ TEST_P(WifiLanTest, AdvertiseDifferentServiceNameUsesDifferentPort) {
NsdServiceInfo nsd_service_info;
nsd_service_info.SetServiceName(std::string(kServiceInfoName));
wifi_lan_server.StartAdvertising(service_id, nsd_service_info, {});
auto [addresses, port] =
std::vector<ServiceAddress> addresses =
wifi_lan_server.GetUpgradeAddressCandidates(service_id);
wifi_lan_server.StopAdvertising(service_id);
wifi_lan_server.StopAcceptingConnections(service_id);
nsd_service_info.SetServiceName("ServiceInfoName2");
wifi_lan_server.StartAdvertising(service_id, nsd_service_info, {});
auto [addresses2, port2] =
std::vector<ServiceAddress> addresses2 =
wifi_lan_server.GetUpgradeAddressCandidates(service_id);
EXPECT_NE(port, port2);
EXPECT_NE(addresses.back().port, addresses2.back().port);
env_.Stop();
}
@@ -317,15 +319,16 @@ TEST_P(WifiLanTest, CanConnectWithIpAddressAndPort) {
accept_latch.CountDown();
}));
auto server_candidates =
std::vector<ServiceAddress> server_candidates =
wifi_lan_server.GetUpgradeAddressCandidates(service_id);
ASSERT_FALSE(server_candidates.first.empty());
ASSERT_NE(server_candidates.second, 0);
ASSERT_FALSE(server_candidates.empty());
ASSERT_NE(server_candidates.back().port, 0);
CancellationFlag flag;
ErrorOr<WifiLanSocket> socket_for_client_result =
wifi_lan_client.Connect(service_id, server_candidates.first.front(),
server_candidates.second, &flag);
std::string ip_address{server_candidates.front().address.begin(),
server_candidates.front().address.end()};
ErrorOr<WifiLanSocket> socket_for_client_result = wifi_lan_client.Connect(
service_id, ip_address, server_candidates.front().port, &flag);
EXPECT_TRUE(accept_latch.Await(kWaitDuration).result());
EXPECT_TRUE(wifi_lan_server.StopAcceptingConnections(service_id));
EXPECT_TRUE(wifi_lan_server.StopAdvertising(service_id));
+13 -9
View File
@@ -32,6 +32,7 @@
#include "internal/platform/implementation/wifi_utils.h"
#include "internal/platform/logging.h"
#include "internal/platform/mac_address.h"
#include "internal/platform/wifi_credential.h"
namespace nearby {
namespace connections {
@@ -289,7 +290,7 @@ ByteArray ForBwuWifiHotspotPathAvailable(
}
ByteArray ForBwuWifiLanPathAvailable(
const std::vector<std::string>& ip_addresses, std::int32_t port) {
const std::vector<ServiceAddress>& addresses) {
OfflineFrame frame;
frame.set_version(OfflineFrame::V1);
@@ -304,18 +305,21 @@ ByteArray ForBwuWifiLanPathAvailable(
auto* wifi_lan_socket = upgrade_path_info->mutable_wifi_lan_socket();
// 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);
const auto& last_address = addresses.back();
if (last_address.address.size() == 4) {
wifi_lan_socket->set_ip_address(
std::string(last_address.address.begin(), last_address.address.end()));
wifi_lan_socket->set_wifi_port(last_address.port);
}
for (const auto& address : ip_addresses) {
for (const auto& address : addresses) {
auto* address_candidate = wifi_lan_socket->add_address_candidates();
std::string ip_address = std::string(address.begin(), address.end());
std::string ip_address =
std::string(address.address.begin(), address.address.end());
address_candidate->set_ip_address(ip_address);
address_candidate->set_port(port);
address_candidate->set_port(address.port);
VLOG(1) << "ForBwuWifiLanPathAvailable: "
<< WifiUtils::GetHumanReadableIpAddress(ip_address) << ":" << port;
<< WifiUtils::GetHumanReadableIpAddress(ip_address) << ":"
<< address.port;
}
return ToBytes(std::move(frame));
}
+2 -1
View File
@@ -25,6 +25,7 @@
#include "internal/platform/byte_array.h"
#include "internal/platform/exception.h"
#include "internal/platform/mac_address.h"
#include "internal/platform/wifi_credential.h"
namespace nearby {
namespace connections {
@@ -83,7 +84,7 @@ ByteArray ForBwuWifiHotspotPathAvailable(
UpgradePathInfo::WifiHotspotCredentials credentials,
bool supports_disabling_encryption);
ByteArray ForBwuWifiLanPathAvailable(
const std::vector<std::string>& ip_addresses, std::int32_t port);
const std::vector<ServiceAddress>& addresses);
ByteArray ForBwuAwdlPathAvailable(const std::string& service_name,
const std::string& service_type,
const std::string& password,
@@ -30,6 +30,7 @@
#include "internal/flags/nearby_flags.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/mac_address.h"
#include "internal/platform/wifi_credential.h"
namespace nearby {
namespace connections {
@@ -532,11 +533,13 @@ TEST(OfflineFramesTest, CanGenerateBwuWifiLanPathAvailable) {
>
>)pb";
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);
{ServiceAddress{
.address = {'\x2a', '\x00', '\x79', '\xe0', '\x2e', '\x87', '\x00',
'\x06', '\xb7', '\x28', '\x67', '\x45', '\x7a', '\xdd',
'\x01', '\x53'},
.port = 1234},
ServiceAddress{.address = {'\x01', '\x02', '\x03', '\x04'},
.port = 1234}});
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = response.result();
@@ -27,6 +27,7 @@
#include "connections/medium_selector.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/exception.h"
#include "internal/platform/wifi_credential.h"
namespace nearby {
namespace connections {
@@ -686,13 +687,13 @@ TEST(OfflineFramesValidatorTest,
TEST(OfflineFramesValidatorTest,
ValidateWifiLanUpgradeFrameWithAddressCandidatesSucceeds) {
OfflineFrame offline_frame;
std::vector<std::string> address_candidates = {
std::string(
"\x2a\x00\x79\xe0\x2e\x87\x00\x06\xb7\x28\x67\x45\x7a\xdd\x01\x53",
16),
std::string("\xc0\xa8\x00\x01", 4),
std::vector<ServiceAddress> address_candidates = {
{{'\x2a', '\x00', '\x79', '\xe0', '\x2e', '\x87', '\x00', '\x06', '\xb7',
'\x28', '\x67', '\x45', '\x7a', '\xdd', '\x01', '\x53'},
kPort},
{{'\xc0', '\xa8', '\x00', '\x01'}, kPort},
};
ByteArray bytes = ForBwuWifiLanPathAvailable(address_candidates, kPort);
ByteArray bytes = ForBwuWifiLanPathAvailable(address_candidates);
offline_frame.ParseFromString(std::string(bytes));
auto ret_value = EnsureValidOfflineFrame(offline_frame);
@@ -145,17 +145,15 @@ ByteArray WifiLanBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
// Address candidates are not populated until StartAcceptingConnections() is
// called and the server socket is created. Be careful moving this codeblock
// around.
std::pair<std::vector<std::string>, int> upgrade_candidates =
std::vector<ServiceAddress> upgrade_candidates =
wifi_lan_medium_.GetUpgradeAddressCandidates(upgrade_service_id);
const std::vector<std::string>& ip_addresses = upgrade_candidates.first;
int port = upgrade_candidates.second;
if (ip_addresses.empty()) {
if (upgrade_candidates.empty()) {
LOG(INFO) << "WifiLanBwuHandler couldn't initiate the wifi_lan upgrade for "
<< "service " << upgrade_service_id << " and endpoint "
<< endpoint_id << " because there are no available ip addresses.";
return {};
}
return parser::ForBwuWifiLanPathAvailable(ip_addresses, port);
return parser::ForBwuWifiLanPathAvailable(upgrade_candidates);
}
void WifiLanBwuHandler::HandleRevertInitiatorStateForService(
@@ -34,6 +34,7 @@
#include "internal/platform/mock_wifi_lan_medium.h"
#include "internal/platform/mock_wifi_lan_server_socket.h"
#include "internal/platform/mock_wifi_lan_socket.h"
#include "internal/platform/wifi_credential.h"
namespace nearby {
@@ -195,8 +196,10 @@ TEST_F(WifiLanBwuHandlerTest, InitializeUpgradedMediumForEndpoint_Success) {
EXPECT_CALL(*wifi_lan_medium, ListenForService(_))
.WillOnce(Return(ByMove(std::move(wifi_lan_server_socket))));
EXPECT_CALL(*wifi_lan_medium, GetUpgradeAddressCandidates(_))
.WillOnce(Return(std::vector<std::string>{std::string(kIpv6Address),
std::string(kIpv4Address)}));
.WillOnce(Return(std::vector<ServiceAddress>{
{std::vector<char>{kIpv6Address.begin(), kIpv6Address.end()}, 8080},
{std::vector<char>{kIpv4Address.begin(), kIpv4Address.end()},
8888}}));
OfflineFrame expected_frame;
expected_frame.set_version(OfflineFrame::V1);
expected_frame.mutable_v1()->set_type(V1Frame::BANDWIDTH_UPGRADE_NEGOTIATION);
@@ -212,13 +215,13 @@ TEST_F(WifiLanBwuHandlerTest, InitializeUpgradedMediumForEndpoint_Success) {
->mutable_upgrade_path_info()
->mutable_wifi_lan_socket();
wifi_lan_socket->set_ip_address(kIpv4Address);
wifi_lan_socket->set_wifi_port(8080);
wifi_lan_socket->set_wifi_port(8888);
auto* address_candidate = wifi_lan_socket->add_address_candidates();
address_candidate->set_ip_address(kIpv6Address);
address_candidate->set_port(8080);
address_candidate = wifi_lan_socket->add_address_candidates();
address_candidate->set_ip_address(kIpv4Address);
address_candidate->set_port(8080);
address_candidate->set_port(8888);
upgrade_path_info->set_supports_client_introduction_ack(true);
ByteArray result = handler_.InitializeUpgradedMediumForEndpoint(
@@ -23,6 +23,7 @@
#include "internal/platform/implementation/wifi_lan.h"
#include "internal/platform/nsd_service_info.h"
#include "internal/platform/wifi_credential.h"
@class GNCNWFramework;
@class GNCNWFrameworkServerSocket;
@@ -124,7 +125,7 @@ class WifiLanMedium : public api::WifiLanMedium {
std::unique_ptr<api::WifiLanSocket> ConnectToService(
const std::string& ip_address, int port, CancellationFlag* cancellation_flag) override;
std::unique_ptr<api::WifiLanServerSocket> ListenForService(int port) override;
std::vector<std::string> GetUpgradeAddressCandidates(const api::WifiLanServerSocket& server_socket) override;
std::vector<ServiceAddress> GetUpgradeAddressCandidates(const api::WifiLanServerSocket& server_socket) override;
private:
GNCNWFramework* medium_;
@@ -183,9 +183,11 @@ std::unique_ptr<api::WifiLanServerSocket> WifiLanMedium::ListenForService(int po
return nil;
}
std::vector<std::string> WifiLanMedium::GetUpgradeAddressCandidates(
std::vector<ServiceAddress> WifiLanMedium::GetUpgradeAddressCandidates(
const api::WifiLanServerSocket& server_socket) {
return { server_socket.GetIPAddress() };
std::string ip_address = server_socket.GetIPAddress();
return {ServiceAddress{.address = std::vector<char>(ip_address.begin(), ip_address.end()),
.port = static_cast<uint16_t>(server_socket.GetPort())}};
}
} // namespace apple
@@ -14,6 +14,7 @@
#include "internal/platform/implementation/g3/wifi_lan.h"
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
@@ -28,6 +29,7 @@
#include "internal/platform/logging.h"
#include "internal/platform/medium_environment.h"
#include "internal/platform/nsd_service_info.h"
#include "internal/platform/wifi_credential.h"
namespace nearby {
namespace g3 {
@@ -282,9 +284,12 @@ std::unique_ptr<api::WifiLanServerSocket> WifiLanMedium::ListenForService(
return server_socket;
}
std::vector<std::string> WifiLanMedium::GetUpgradeAddressCandidates(
std::vector<ServiceAddress> WifiLanMedium::GetUpgradeAddressCandidates(
const api::WifiLanServerSocket& server_socket) {
return { server_socket.GetIPAddress() };
std::string ip_address = server_socket.GetIPAddress();
return {ServiceAddress{
.address = std::vector<char>(ip_address.begin(), ip_address.end()),
.port = static_cast<uint16_t>(server_socket.GetPort())}};
}
} // namespace g3
@@ -29,6 +29,7 @@
#include "internal/platform/medium_environment.h"
#include "internal/platform/nsd_service_info.h"
#include "internal/platform/output_stream.h"
#include "internal/platform/wifi_credential.h"
namespace nearby {
namespace g3 {
@@ -207,7 +208,7 @@ class WifiLanMedium : public api::WifiLanMedium {
return std::nullopt;
}
std::vector<std::string> GetUpgradeAddressCandidates(
std::vector<ServiceAddress> GetUpgradeAddressCandidates(
const api::WifiLanServerSocket& server_socket) override;
private:
+2 -1
View File
@@ -25,6 +25,7 @@
#include "internal/platform/listeners.h"
#include "internal/platform/nsd_service_info.h"
#include "internal/platform/output_stream.h"
#include "internal/platform/wifi_credential.h"
namespace nearby {
namespace api {
@@ -160,7 +161,7 @@ class WifiLanMedium {
// requests.
// Returned adddress list is sorted so IPv6 addresses are first. Both IPv4
// and IPv6 addresses are represented as network order byte sequence.
virtual std::vector<std::string> GetUpgradeAddressCandidates(
virtual std::vector<ServiceAddress> GetUpgradeAddressCandidates(
const WifiLanServerSocket& server_socket) = 0;
};
@@ -27,6 +27,7 @@
#include <optional>
#include <string>
#include <utility>
#include <vector>
// Nearby connections headers
#include "absl/base/nullability.h"
@@ -50,6 +51,7 @@
#include "internal/platform/input_stream.h"
#include "internal/platform/nsd_service_info.h"
#include "internal/platform/output_stream.h"
#include "internal/platform/wifi_credential.h"
// WinRT headers
#include "internal/platform/implementation/windows/generated/winrt/Windows.Devices.Enumeration.h"
@@ -182,7 +184,7 @@ class WifiLanMedium : public api::WifiLanMedium {
return absl::nullopt;
}
std::vector<std::string> GetUpgradeAddressCandidates(
std::vector<ServiceAddress> GetUpgradeAddressCandidates(
const api::WifiLanServerSocket& server_socket) override;
private:
@@ -40,6 +40,7 @@
#include "internal/platform/exception.h"
#include "internal/platform/feature_flags.h"
#include "internal/platform/flags/nearby_platform_feature_flags.h"
#include "internal/platform/wifi_credential.h"
#include "internal/platform/implementation/wifi_lan.h"
#include "internal/platform/implementation/windows/generated/winrt/Windows.Devices.Enumeration.h"
#include "internal/platform/implementation/windows/generated/winrt/Windows.Foundation.Collections.h"
@@ -735,11 +736,12 @@ bool WifiLanMedium::IsConnectableIpAddress(NsdServiceInfo& nsd_service_info,
return false;
}
std::vector<std::string> WifiLanMedium::GetUpgradeAddressCandidates(
std::vector<ServiceAddress> WifiLanMedium::GetUpgradeAddressCandidates(
const api::WifiLanServerSocket& server_socket) {
const NetworkInfo& network_info = NetworkInfo::GetNetworkInfo();
std::vector<std::string> ip_addresses;
std::vector<std::string> ipv4_addresses;
uint16_t port = server_socket.GetPort();
std::vector<ServiceAddress> ip_addresses;
std::vector<ServiceAddress> ipv4_addresses;
for (const auto& net_interface : network_info.GetInterfaces()) {
// Only use wifi and ethernet interfaces for upgrade.
if (net_interface.type != InterfaceType::kWifi &&
@@ -753,16 +755,22 @@ std::vector<std::string> WifiLanMedium::GetUpgradeAddressCandidates(
if (address.IsV6LinkLocal()) {
continue;
}
ip_addresses.push_back(
std::string(reinterpret_cast<const char*>(
&address.ipv6_address()->sin6_addr.u.Byte[0]),
16));
ip_addresses.push_back(ServiceAddress{
.address =
std::vector<char>(address.ipv6_address()->sin6_addr.u.Byte,
address.ipv6_address()->sin6_addr.u.Byte + 16),
.port = port,
});
}
for (const auto& ipv4address : net_interface.ipv4_addresses) {
auto address = reinterpret_cast<const sockaddr_in*>(&ipv4address);
ipv4_addresses.push_back(std::string(
reinterpret_cast<const char*>(&address->sin_addr.S_un.S_un_b.s_b1),
4));
ipv4_addresses.push_back(ServiceAddress{
.address = {address->sin_addr.S_un.S_un_b.s_b1,
address->sin_addr.S_un.S_un_b.s_b2,
address->sin_addr.S_un.S_un_b.s_b3,
address->sin_addr.S_un.S_un_b.s_b4},
.port = port,
});
}
}
if (NearbyFlags::GetInstance().GetBoolFlag(
+2 -1
View File
@@ -26,6 +26,7 @@
#include "internal/platform/cancellation_flag.h"
#include "internal/platform/implementation/wifi_lan.h"
#include "internal/platform/nsd_service_info.h"
#include "internal/platform/wifi_credential.h"
namespace nearby {
@@ -54,7 +55,7 @@ class MockWifiLanMedium : public api::WifiLanMedium {
(int port), (override));
MOCK_METHOD((absl::optional<std::pair<std::int32_t, std::int32_t>>),
GetDynamicPortRange, (), (override));
MOCK_METHOD(std::vector<std::string>, GetUpgradeAddressCandidates,
MOCK_METHOD(std::vector<ServiceAddress>, GetUpgradeAddressCandidates,
(const api::WifiLanServerSocket& server_socket), (override));
};
+2 -1
View File
@@ -27,6 +27,7 @@
#include "internal/platform/nsd_service_info.h"
#include "internal/platform/output_stream.h"
#include "internal/platform/socket.h"
#include "internal/platform/wifi_credential.h"
namespace nearby {
using location::nearby::proto::connections::Medium;
@@ -202,7 +203,7 @@ WifiLanSocket WifiLanMedium::ConnectToService(
impl_->ConnectToService(ip_address, port, cancellation_flag));
}
std::vector<std::string> WifiLanMedium::GetUpgradeAddressCandidates(
std::vector<ServiceAddress> WifiLanMedium::GetUpgradeAddressCandidates(
const WifiLanServerSocket& server_socket) {
return impl_->GetUpgradeAddressCandidates(server_socket.GetImpl());
}
+2 -1
View File
@@ -37,6 +37,7 @@
#include "internal/platform/nsd_service_info.h"
#include "internal/platform/output_stream.h"
#include "internal/platform/socket.h"
#include "internal/platform/wifi_credential.h"
namespace nearby {
@@ -275,7 +276,7 @@ class WifiLanMedium {
// requests.
// Returned adddress list is sorted so IPv6 addresses are first. Both IPv4
// and IPv6 addresses are represented as network order byte sequence.
std::vector<std::string> GetUpgradeAddressCandidates(
std::vector<ServiceAddress> GetUpgradeAddressCandidates(
const WifiLanServerSocket& server_socket);
private: