mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Log interface count and IPv6 only interface count during wifi upgrade.
PiperOrigin-RevId: 852845375
This commit is contained in:
committed by
Copybara-Service
parent
6cc697cc56
commit
1b557236f7
@@ -159,6 +159,7 @@ cc_library(
|
||||
"credential_storage.h",
|
||||
"http_loader.h",
|
||||
"psk_info.h",
|
||||
"upgrade_address_info.h",
|
||||
"webrtc.h",
|
||||
"wifi.h",
|
||||
"wifi_direct.h",
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "internal/platform/implementation/upgrade_address_info.h"
|
||||
#include "internal/platform/implementation/wifi_lan.h"
|
||||
#include "internal/platform/nsd_service_info.h"
|
||||
#include "internal/platform/service_address.h"
|
||||
@@ -125,7 +126,7 @@ class WifiLanMedium : public api::WifiLanMedium {
|
||||
std::unique_ptr<api::WifiLanSocket> ConnectToService(
|
||||
const ServiceAddress& service_address, CancellationFlag* cancellation_flag) override;
|
||||
std::unique_ptr<api::WifiLanServerSocket> ListenForService(int port) override;
|
||||
std::vector<ServiceAddress> GetUpgradeAddressCandidates(const api::WifiLanServerSocket& server_socket) override;
|
||||
api::UpgradeAddressInfo GetUpgradeAddressCandidates(const api::WifiLanServerSocket& server_socket) override;
|
||||
|
||||
private:
|
||||
GNCNWFramework* medium_;
|
||||
|
||||
@@ -183,11 +183,16 @@ std::unique_ptr<api::WifiLanServerSocket> WifiLanMedium::ListenForService(int po
|
||||
return nil;
|
||||
}
|
||||
|
||||
std::vector<ServiceAddress> WifiLanMedium::GetUpgradeAddressCandidates(
|
||||
api::UpgradeAddressInfo WifiLanMedium::GetUpgradeAddressCandidates(
|
||||
const api::WifiLanServerSocket& server_socket) {
|
||||
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())}};
|
||||
api::UpgradeAddressInfo result;
|
||||
result.num_interfaces = 1;
|
||||
result.num_ipv6_only_interfaces = 0;
|
||||
result.address_candidates.push_back(
|
||||
{.address = std::vector<char>(ip_address.begin(), ip_address.end()),
|
||||
.port = static_cast<uint16_t>(server_socket.GetPort())});
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace apple
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/cancellation_flag_listener.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/implementation/upgrade_address_info.h"
|
||||
#include "internal/platform/implementation/wifi_lan.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
@@ -289,12 +290,17 @@ std::unique_ptr<api::WifiLanServerSocket> WifiLanMedium::ListenForService(
|
||||
return server_socket;
|
||||
}
|
||||
|
||||
std::vector<ServiceAddress> WifiLanMedium::GetUpgradeAddressCandidates(
|
||||
api::UpgradeAddressInfo WifiLanMedium::GetUpgradeAddressCandidates(
|
||||
const api::WifiLanServerSocket& server_socket) {
|
||||
std::string ip_address = server_socket.GetIPAddress();
|
||||
return {ServiceAddress{
|
||||
return {
|
||||
.num_interfaces = 1,
|
||||
.num_ipv6_only_interfaces = 0,
|
||||
.address_candidates =
|
||||
{ServiceAddress{
|
||||
.address = std::vector<char>(ip_address.begin(), ip_address.end()),
|
||||
.port = static_cast<uint16_t>(server_socket.GetPort())}};
|
||||
.port = static_cast<uint16_t>(server_socket.GetPort())}}
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace g3
|
||||
|
||||
@@ -18,19 +18,18 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/implementation/g3/socket_base.h"
|
||||
#include "internal/platform/implementation/upgrade_address_info.h"
|
||||
#include "internal/platform/implementation/wifi_lan.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/nsd_service_info.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
#include "internal/platform/service_address.h"
|
||||
#include "internal/platform/wifi_credential.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace g3 {
|
||||
@@ -209,7 +208,7 @@ class WifiLanMedium : public api::WifiLanMedium {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::vector<ServiceAddress> GetUpgradeAddressCandidates(
|
||||
api::UpgradeAddressInfo GetUpgradeAddressCandidates(
|
||||
const api::WifiLanServerSocket& server_socket) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright 2025 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_IMPLEMENTATION_UPGRADE_ADDRESS_INFO_H_
|
||||
#define THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_UPGRADE_ADDRESS_INFO_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include "internal/platform/service_address.h"
|
||||
|
||||
namespace nearby::api {
|
||||
|
||||
// Container for upgrade address candidates and network configuration info.
|
||||
struct UpgradeAddressInfo {
|
||||
// Number of network interfaces that can be used for upgrade.
|
||||
int num_interfaces = 0;
|
||||
// Number of network interfaces for upgrade that are IPv6 only.
|
||||
int num_ipv6_only_interfaces = 0;
|
||||
// Address list is sorted so IPv6 addresses are first.
|
||||
std::vector<ServiceAddress> address_candidates;
|
||||
};
|
||||
|
||||
} // namespace nearby::api
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_UPGRADE_ADDRESS_INFO_H_
|
||||
@@ -17,10 +17,10 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/implementation/upgrade_address_info.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/listeners.h"
|
||||
#include "internal/platform/nsd_service_info.h"
|
||||
@@ -159,9 +159,7 @@ class WifiLanMedium {
|
||||
// this device for bandwidth upgrade.
|
||||
// `server_socket` is the socket that is currently listening for service
|
||||
// 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<ServiceAddress> GetUpgradeAddressCandidates(
|
||||
virtual UpgradeAddressInfo GetUpgradeAddressCandidates(
|
||||
const WifiLanServerSocket& server_socket) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -309,7 +309,6 @@ cc_library(
|
||||
"//internal/platform:comm",
|
||||
"//internal/platform:logging",
|
||||
"//internal/platform:mac_address",
|
||||
"//internal/platform:types",
|
||||
"//internal/platform:uuid",
|
||||
"//internal/platform/flags:platform_flags",
|
||||
"//internal/platform/implementation:comm",
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
// Nearby connections headers
|
||||
#include "absl/base/nullability.h"
|
||||
@@ -38,10 +37,10 @@
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/implementation/cancelable.h"
|
||||
#include "internal/platform/implementation/upgrade_address_info.h"
|
||||
#include "internal/platform/implementation/wifi_lan.h"
|
||||
#include "internal/platform/implementation/windows/nearby_client_socket.h"
|
||||
#include "internal/platform/implementation/windows/nearby_server_socket.h"
|
||||
@@ -52,7 +51,6 @@
|
||||
#include "internal/platform/nsd_service_info.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
#include "internal/platform/service_address.h"
|
||||
#include "internal/platform/wifi_credential.h"
|
||||
|
||||
// WinRT headers
|
||||
#include "internal/platform/implementation/windows/generated/winrt/Windows.Devices.Enumeration.h"
|
||||
@@ -185,7 +183,7 @@ class WifiLanMedium : public api::WifiLanMedium {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
std::vector<ServiceAddress> GetUpgradeAddressCandidates(
|
||||
api::UpgradeAddressInfo GetUpgradeAddressCandidates(
|
||||
const api::WifiLanServerSocket& server_socket) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
@@ -42,6 +41,7 @@
|
||||
#include "internal/platform/feature_flags.h"
|
||||
#include "internal/platform/flags/nearby_platform_feature_flags.h"
|
||||
#include "internal/platform/service_address.h"
|
||||
#include "internal/platform/implementation/upgrade_address_info.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"
|
||||
@@ -717,13 +717,16 @@ bool WifiLanMedium::IsConnectableIpAddress(NsdServiceInfo& nsd_service_info,
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<ServiceAddress> WifiLanMedium::GetUpgradeAddressCandidates(
|
||||
api::UpgradeAddressInfo WifiLanMedium::GetUpgradeAddressCandidates(
|
||||
const api::WifiLanServerSocket& server_socket) {
|
||||
const NetworkInfo& network_info = NetworkInfo::GetNetworkInfo();
|
||||
uint16_t port = server_socket.GetPort();
|
||||
std::vector<ServiceAddress> ip_addresses;
|
||||
api::UpgradeAddressInfo result;
|
||||
std::vector<ServiceAddress> ipv4_addresses;
|
||||
for (const auto& net_interface : network_info.GetInterfaces()) {
|
||||
for (const NetworkInfo::InterfaceInfo& net_interface :
|
||||
network_info.GetInterfaces()) {
|
||||
bool has_ipv6_address = false;
|
||||
bool has_ipv4_address = false;
|
||||
// Only use wifi and ethernet interfaces for upgrade.
|
||||
if (net_interface.type != InterfaceType::kWifi &&
|
||||
net_interface.type != InterfaceType::kEthernet) {
|
||||
@@ -735,24 +738,41 @@ std::vector<ServiceAddress> WifiLanMedium::GetUpgradeAddressCandidates(
|
||||
if (address.IsV6LinkLocal()) {
|
||||
continue;
|
||||
}
|
||||
ip_addresses.push_back(address.ToServiceAddress(port));
|
||||
result.address_candidates.push_back(address.ToServiceAddress(port));
|
||||
has_ipv6_address = true;
|
||||
}
|
||||
for (const SocketAddress& v4_address : net_interface.ipv4_addresses) {
|
||||
// Link local addresses cannot be used for upgrade since we can't tell
|
||||
// which interface on the remote device the address is valid.
|
||||
if (v4_address.IsV4LinkLocal()) {
|
||||
continue;
|
||||
}
|
||||
ipv4_addresses.push_back(v4_address.ToServiceAddress(port));
|
||||
has_ipv4_address = true;
|
||||
}
|
||||
if (has_ipv6_address || has_ipv4_address) {
|
||||
result.num_interfaces++;
|
||||
if (has_ipv6_address && !has_ipv4_address) {
|
||||
result.num_ipv6_only_interfaces++;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
result.address_candidates.insert(result.address_candidates.end(),
|
||||
ipv4_addresses.begin(),
|
||||
ipv4_addresses.end());
|
||||
} else {
|
||||
// If kEnableWifiLanAddressCandidates is disabled, only return the last v4
|
||||
// address.
|
||||
result.address_candidates.clear();
|
||||
if (!ipv4_addresses.empty()) {
|
||||
result.address_candidates.push_back(ipv4_addresses.back());
|
||||
}
|
||||
}
|
||||
if (!ipv4_addresses.empty()) {
|
||||
return {ipv4_addresses.back()};
|
||||
}
|
||||
return {};
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace nearby::windows
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/implementation/upgrade_address_info.h"
|
||||
#include "internal/platform/implementation/wifi_lan.h"
|
||||
#include "internal/platform/nsd_service_info.h"
|
||||
#include "internal/platform/service_address.h"
|
||||
@@ -55,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<ServiceAddress>, GetUpgradeAddressCandidates,
|
||||
MOCK_METHOD(api::UpgradeAddressInfo, GetUpgradeAddressCandidates,
|
||||
(const api::WifiLanServerSocket& server_socket), (override));
|
||||
};
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/implementation/upgrade_address_info.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/mutex_lock.h"
|
||||
#include "internal/platform/nsd_service_info.h"
|
||||
@@ -201,7 +201,7 @@ WifiLanSocket WifiLanMedium::ConnectToService(
|
||||
impl_->ConnectToService(service_address, cancellation_flag));
|
||||
}
|
||||
|
||||
std::vector<ServiceAddress> WifiLanMedium::GetUpgradeAddressCandidates(
|
||||
api::UpgradeAddressInfo WifiLanMedium::GetUpgradeAddressCandidates(
|
||||
const WifiLanServerSocket& server_socket) {
|
||||
return impl_->GetUpgradeAddressCandidates(server_socket.GetImpl());
|
||||
}
|
||||
|
||||
@@ -19,9 +19,10 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/base/thread_annotations.h"
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "internal/platform/blocking_queue_stream.h"
|
||||
@@ -29,6 +30,7 @@
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/implementation/platform.h"
|
||||
#include "internal/platform/implementation/upgrade_address_info.h"
|
||||
#include "internal/platform/implementation/wifi_lan.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/listeners.h"
|
||||
@@ -189,8 +191,6 @@ class WifiLanServerSocket final {
|
||||
// Container of operations that can be performed over the WifiLan medium.
|
||||
class WifiLanMedium {
|
||||
public:
|
||||
using Platform = api::ImplementationPlatform;
|
||||
|
||||
struct DiscoveredServiceCallback {
|
||||
absl::AnyInvocable<void(NsdServiceInfo service_info,
|
||||
const std::string& service_type)>
|
||||
@@ -206,7 +206,7 @@ class WifiLanMedium {
|
||||
DiscoveredServiceCallback medium_callback;
|
||||
};
|
||||
|
||||
WifiLanMedium() : impl_(Platform::CreateWifiLanMedium()) {}
|
||||
WifiLanMedium() : impl_(api::ImplementationPlatform::CreateWifiLanMedium()) {}
|
||||
~WifiLanMedium() = default;
|
||||
|
||||
// Starts WifiLan advertising.
|
||||
@@ -274,9 +274,7 @@ class WifiLanMedium {
|
||||
// this device for bandwidth upgrade.
|
||||
// `server_socket` is the socket that is currently listening for service
|
||||
// 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<ServiceAddress> GetUpgradeAddressCandidates(
|
||||
api::UpgradeAddressInfo GetUpgradeAddressCandidates(
|
||||
const WifiLanServerSocket& server_socket);
|
||||
|
||||
private:
|
||||
|
||||
@@ -556,6 +556,13 @@ message ConnectionsLog {
|
||||
// The supported service.
|
||||
optional location.nearby.proto.connections.SupportedService
|
||||
supported_service = 11;
|
||||
|
||||
// The number of network interfaces on the device for the upgrade medium
|
||||
// that can be used for bandwidth upgrade.
|
||||
optional int32 num_interfaces = 12;
|
||||
// The number of network interfaces on the device for the upgrade medium
|
||||
// that can be used for bandwidth upgrade and are IPv6 only.
|
||||
optional int32 num_ipv6_only_interfaces = 13;
|
||||
}
|
||||
|
||||
// Next Id: 22
|
||||
|
||||
Reference in New Issue
Block a user