Fix code style.

PiperOrigin-RevId: 831606257
This commit is contained in:
Francis Tsui
2025-11-12 17:37:55 -08:00
committed by Copybara-Service
parent fcee77457f
commit ee1a46c3da
22 changed files with 169 additions and 139 deletions
@@ -45,6 +45,7 @@ namespace nearby {
namespace connections {
namespace {
using ::location::nearby::connections::BandwidthUpgradeNegotiationFrame;
using ::location::nearby::proto::connections::OperationResultCode;
constexpr absl::Duration kAwdlDiscoveryTimeout = absl::Seconds(5);
@@ -64,14 +65,16 @@ AwdlBwuHandler::AwdlBwuHandler(
ErrorOr<std::unique_ptr<EndpointChannel>>
AwdlBwuHandler::CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id, const UpgradePathInfo& upgrade_path_info) {
const std::string& endpoint_id,
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo&
upgrade_path_info) {
std::string upgrade_service_id = WrapInitiatorUpgradeServiceId(service_id);
if (!upgrade_path_info.has_awdl_credentials()) {
return {Error(OperationResultCode::CONNECTIVITY_AWDL_INVALID_CREDENTIAL)};
}
const UpgradePathInfo::AwdlCredentials& awdl_credentials =
upgrade_path_info.awdl_credentials();
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo::AwdlCredentials&
awdl_credentials = upgrade_path_info.awdl_credentials();
if (!awdl_credentials.has_service_name() ||
!awdl_credentials.has_service_type() ||
!awdl_credentials.has_password()) {
@@ -59,7 +59,8 @@ class AwdlBwuHandler : public BaseBwuHandler {
ErrorOr<std::unique_ptr<EndpointChannel>> CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info) override;
const location::nearby::connections::BandwidthUpgradeNegotiationFrame::
UpgradePathInfo& upgrade_path_info) override;
location::nearby::proto::connections::Medium GetUpgradeMedium() const final {
return location::nearby::proto::connections::Medium::AWDL;
}
@@ -14,10 +14,13 @@
#include "connections/implementation/base_bwu_handler.h"
#include <memory>
#include <string>
#include <utility>
#include "connections/implementation/client_proxy.h"
#include "connections/implementation/service_id_constants.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/logging.h"
namespace nearby {
@@ -19,9 +19,10 @@
#include <string>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/string_view.h"
#include "absl/container/flat_hash_set.h"
#include "connections/implementation/bwu_handler.h"
#include "connections/implementation/endpoint_channel_manager.h"
#include "connections/implementation/client_proxy.h"
#include "internal/platform/byte_array.h"
namespace nearby {
namespace connections {
@@ -30,7 +30,7 @@
namespace nearby {
namespace connections {
namespace {
using ::location::nearby::connections::BandwidthUpgradeNegotiationFrame;
using ::location::nearby::proto::connections::OperationResultCode;
// Because BaseBwuHandler is still an abstract class, we need to implement the
@@ -61,11 +61,11 @@ class BwuHandlerImpl : public BaseBwuHandler {
private:
// BwuHandler implementation:
ErrorOr<std::unique_ptr<EndpointChannel>>
CreateUpgradedEndpointChannel(
ErrorOr<std::unique_ptr<EndpointChannel>> CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info) final {
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo&
upgrade_path_info) final {
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
}
Medium GetUpgradeMedium() const final { return Medium::UNKNOWN_MEDIUM; }
@@ -39,6 +39,7 @@ namespace nearby {
namespace connections {
namespace {
using ::location::nearby::connections::BandwidthUpgradeNegotiationFrame;
using ::location::nearby::proto::connections::OperationResultCode;
} // namespace
@@ -53,9 +54,11 @@ BluetoothBwuHandler::BluetoothBwuHandler(
ErrorOr<std::unique_ptr<EndpointChannel>>
BluetoothBwuHandler::CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id, const UpgradePathInfo& upgrade_path_info) {
const UpgradePathInfo::BluetoothCredentials& bluetooth_credentials =
upgrade_path_info.bluetooth_credentials();
const std::string& endpoint_id,
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo&
upgrade_path_info) {
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo::BluetoothCredentials&
bluetooth_credentials = upgrade_path_info.bluetooth_credentials();
if (!bluetooth_credentials.has_service_name() ||
!bluetooth_credentials.has_mac_address()) {
LOG(ERROR) << "BluetoothBwuHandler failed to parse UpgradePathInfo.";
@@ -17,7 +17,6 @@
#include <memory>
#include <string>
#include <utility>
#include "connections/implementation/base_bwu_handler.h"
#include "connections/implementation/client_proxy.h"
@@ -57,11 +56,11 @@ class BluetoothBwuHandler : public BaseBwuHandler {
};
// BwuHandler implementation:
ErrorOr<std::unique_ptr<EndpointChannel>>
CreateUpgradedEndpointChannel(ClientProxy* client,
const std::string& service_id,
const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info) final;
ErrorOr<std::unique_ptr<EndpointChannel>> CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id,
const location::nearby::connections::BandwidthUpgradeNegotiationFrame::
UpgradePathInfo& upgrade_path_info) final;
Medium GetUpgradeMedium() const final { return Medium::BLUETOOTH; }
void OnEndpointDisconnect(ClientProxy* client,
const std::string& endpoint_id) final {}
+5 -10
View File
@@ -21,22 +21,16 @@
#include "absl/functional/any_invocable.h"
#include "connections/implementation/client_proxy.h"
#include "connections/implementation/endpoint_channel.h"
#include "connections/implementation/offline_frames.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/expected.h"
namespace nearby {
namespace connections {
using BwuNegotiationFrame =
location::nearby::connections::BandwidthUpgradeNegotiationFrame;
// Defines the set of methods that need to be implemented to handle the
// per-Medium-specific operations needed to upgrade an EndpointChannel.
class BwuHandler {
public:
using UpgradePathInfo = parser::UpgradePathInfo;
class IncomingSocket {
public:
virtual ~IncomingSocket() = default;
@@ -83,10 +77,11 @@ class BwuHandler {
// Initiator, and returns a new EndpointChannel for the upgraded medium.
// @BwuHandlerThread
virtual ErrorOr<std::unique_ptr<EndpointChannel>>
CreateUpgradedEndpointChannel(ClientProxy* client,
const std::string& service_id,
const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info) = 0;
CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id,
const location::nearby::connections::BandwidthUpgradeNegotiationFrame::
UpgradePathInfo& upgrade_path_info) = 0;
// Returns the upgrade medium of the BwuHandler.
// @BwuHandlerThread
+26 -19
View File
@@ -352,7 +352,7 @@ void BwuManager::InitiateBwuForEndpoint(ClientProxy* client,
proposed_medium)
<< " because it failed to initialize the "
"BWU_NEGOTIATION.UPGRADE_PATH_AVAILABLE OfflineFrame.";
UpgradePathInfo info;
BandwidthUpgradeNegotiationFrame::UpgradePathInfo info;
info.set_medium(parser::MediumToUpgradePathInfoMedium(proposed_medium));
ProcessUpgradeFailureEvent(
@@ -373,7 +373,7 @@ void BwuManager::InitiateBwuForEndpoint(ClientProxy* client,
proposed_medium)
<< " because it failed to write the "
"BWU_NEGOTIATION.UPGRADE_PATH_AVAILABLE OfflineFrame.";
UpgradePathInfo info;
BandwidthUpgradeNegotiationFrame::UpgradePathInfo info;
info.set_medium(parser::MediumToUpgradePathInfoMedium(proposed_medium));
ProcessUpgradeFailureEvent(
@@ -547,11 +547,12 @@ BwuHandler* BwuManager::GetHandlerForMedium(Medium medium) const {
return it->second.get();
}
void BwuManager::OnBwuNegotiationFrame(ClientProxy* client,
const BwuNegotiationFrame frame,
const std::string& endpoint_id) {
void BwuManager::OnBwuNegotiationFrame(
ClientProxy* client, const BandwidthUpgradeNegotiationFrame frame,
const std::string& endpoint_id) {
LOG(INFO) << "OnBwuNegotiationFrame: processing incoming "
<< BwuNegotiationFrame::EventType_Name(frame.event_type())
<< BandwidthUpgradeNegotiationFrame::EventType_Name(
frame.event_type())
<< " frame for endpoint " << endpoint_id;
if (!client->IsConnectedToEndpoint(endpoint_id)) {
@@ -564,28 +565,29 @@ void BwuManager::OnBwuNegotiationFrame(ClientProxy* client,
// advertise side already get, discover side should inform advertise side
// the upgrade failed, so the advertise side could have chance to initialize
// another upgrade flow again.
if (frame.event_type() == BwuNegotiationFrame::UPGRADE_PATH_AVAILABLE) {
if (frame.event_type() ==
BandwidthUpgradeNegotiationFrame::UPGRADE_PATH_AVAILABLE) {
RunUpgradeFailedProtocol(client, endpoint_id, frame.upgrade_path_info());
}
return;
}
switch (frame.event_type()) {
case BwuNegotiationFrame::UPGRADE_PATH_AVAILABLE:
case BandwidthUpgradeNegotiationFrame::UPGRADE_PATH_AVAILABLE:
ProcessBwuPathAvailableEvent(client, endpoint_id,
frame.upgrade_path_info());
break;
case BwuNegotiationFrame::UPGRADE_FAILURE:
case BandwidthUpgradeNegotiationFrame::UPGRADE_FAILURE:
ProcessUpgradeFailureEvent(
client, endpoint_id, frame.upgrade_path_info(),
BandwidthUpgradeResult::REMOTE_CONNECTION_ERROR,
/* record_analytic= */ true,
OperationResultCode::NEARBY_GENERIC_REMOTE_UPGRADE_FAILURE);
break;
case BwuNegotiationFrame::LAST_WRITE_TO_PRIOR_CHANNEL:
case BandwidthUpgradeNegotiationFrame::LAST_WRITE_TO_PRIOR_CHANNEL:
ProcessLastWriteToPriorChannelEvent(client, endpoint_id);
break;
case BwuNegotiationFrame::SAFE_TO_CLOSE_PRIOR_CHANNEL:
case BandwidthUpgradeNegotiationFrame::SAFE_TO_CLOSE_PRIOR_CHANNEL:
ProcessSafeToClosePriorChannelEvent(client, endpoint_id);
break;
default:
@@ -623,7 +625,7 @@ void BwuManager::OnIncomingConnection(
VLOG(1) << "BwuManager successfully created new EndpointChannel for "
"incoming socket";
ClientIntroduction introduction;
BandwidthUpgradeNegotiationFrame::ClientIntroduction introduction;
if (!ReadClientIntroductionFrame(channel, introduction)) {
// This was never a fully EstablishedConnection, no need to provide a
// closure reason.
@@ -776,7 +778,8 @@ void BwuManager::RunUpgradeProtocol(
// Outgoing BWU session.
void BwuManager::ProcessBwuPathAvailableEvent(
ClientProxy* client, const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info) {
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo&
upgrade_path_info) {
Medium upgrade_medium =
parser::UpgradePathInfoMediumToMedium(upgrade_path_info.medium());
LOG(INFO) << "ProcessBwuPathAvailableEvent for endpoint " << endpoint_id
@@ -925,7 +928,8 @@ void BwuManager::ProcessBwuPathAvailableEvent(
ErrorOr<std::unique_ptr<EndpointChannel>>
BwuManager::ProcessBwuPathAvailableEventInternal(
ClientProxy* client, const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info) {
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo&
upgrade_path_info) {
Medium medium =
parser::UpgradePathInfoMediumToMedium(upgrade_path_info.medium());
if (medium != GetBwuMediumForEndpoint(endpoint_id)) {
@@ -1064,7 +1068,8 @@ BwuManager::ProcessBwuPathAvailableEventInternal(
void BwuManager::RunUpgradeFailedProtocol(
ClientProxy* client, const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info) {
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo&
upgrade_path_info) {
LOG(INFO) << "RunUpgradeFailedProtocol for endpoint " << endpoint_id
<< " medium "
<< location::nearby::proto::connections::Medium_Name(
@@ -1111,8 +1116,9 @@ void BwuManager::RunUpgradeFailedProtocol(
<< " that the bandwidth upgrade failed.";
}
bool BwuManager::ReadClientIntroductionFrame(EndpointChannel* channel,
ClientIntroduction& introduction) {
bool BwuManager::ReadClientIntroductionFrame(
EndpointChannel* channel,
BandwidthUpgradeNegotiationFrame::ClientIntroduction& introduction) {
LOG(INFO) << "ReadClientIntroductionFrame with channel name: "
<< channel->GetName() << ", medium: "
<< location::nearby::proto::connections::Medium_Name(
@@ -1346,8 +1352,9 @@ void BwuManager::ProcessSafeToClosePriorChannelEvent(
void BwuManager::ProcessUpgradeFailureEvent(
ClientProxy* client, const std::string& endpoint_id,
const UpgradePathInfo& upgrade_info, BandwidthUpgradeResult result,
bool record_analytic, OperationResultCode operation_result_code) {
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo& upgrade_info,
BandwidthUpgradeResult result, bool record_analytic,
OperationResultCode operation_result_code) {
LOG(INFO) << "ProcessUpgradeFailureEvent for endpoint " << endpoint_id
<< " from medium: "
<< location::nearby::proto::connections::Medium_Name(
+25 -18
View File
@@ -66,8 +66,6 @@ namespace connections {
// other, and upon doing so, close the prior EndpointChannel.
class BwuManager : public EndpointManager::FrameProcessor {
public:
using UpgradePathInfo = BwuHandler::UpgradePathInfo;
struct Config {
BooleanMediumSelector allow_upgrade_to;
absl::Duration bandwidth_upgrade_retry_delay;
@@ -139,13 +137,16 @@ class BwuManager : public EndpointManager::FrameProcessor {
const std::vector<Medium>& mediums) const;
// BaseBwuHandler
using ClientIntroduction = BwuNegotiationFrame::ClientIntroduction;
// Processes the BwuNegotiationFrames that come over the EndpointChannel on
// both initiator and responder side of the upgrade.
void OnBwuNegotiationFrame(ClientProxy* client,
const BwuNegotiationFrame frame,
const string& endpoint_id);
// Processes the
// location::nearby::connections::BandwidthUpgradeNegotiationFrames that come
// over the EndpointChannel on both initiator and responder side of the
// upgrade.
void OnBwuNegotiationFrame(
ClientProxy* client,
const location::nearby::connections::BandwidthUpgradeNegotiationFrame
frame,
const string& endpoint_id);
// Called to revert any state changed in the course of setting up the upgraded
// medium for an endpoint.
@@ -170,22 +171,27 @@ class BwuManager : public EndpointManager::FrameProcessor {
void RunUpgradeProtocol(ClientProxy* client, const std::string& endpoint_id,
std::unique_ptr<EndpointChannel> new_channel,
bool enable_encryption);
void RunUpgradeFailedProtocol(ClientProxy* client,
const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info);
void ProcessBwuPathAvailableEvent(ClientProxy* client,
const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info);
void RunUpgradeFailedProtocol(
ClientProxy* client, const std::string& endpoint_id,
const location::nearby::connections::BandwidthUpgradeNegotiationFrame::
UpgradePathInfo& upgrade_path_info);
void ProcessBwuPathAvailableEvent(
ClientProxy* client, const std::string& endpoint_id,
const location::nearby::connections::BandwidthUpgradeNegotiationFrame::
UpgradePathInfo& upgrade_path_info);
ErrorOr<std::unique_ptr<EndpointChannel>>
ProcessBwuPathAvailableEventInternal(
ClientProxy* client, const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info);
const location::nearby::connections::BandwidthUpgradeNegotiationFrame::
UpgradePathInfo& upgrade_path_info);
void ProcessLastWriteToPriorChannelEvent(ClientProxy* client,
const std::string& endpoint_id);
void ProcessSafeToClosePriorChannelEvent(ClientProxy* client,
const std::string& endpoint_id);
bool ReadClientIntroductionFrame(EndpointChannel* endpoint_channel,
ClientIntroduction& introduction);
bool ReadClientIntroductionFrame(
EndpointChannel* endpoint_channel,
location::nearby::connections::BandwidthUpgradeNegotiationFrame::
ClientIntroduction& introduction);
bool ReadClientIntroductionAckFrame(EndpointChannel* endpoint_channel);
bool WriteClientIntroductionAckFrame(EndpointChannel* endpoint_channel);
void ProcessEndpointDisconnection(ClientProxy* client,
@@ -193,7 +199,8 @@ class BwuManager : public EndpointManager::FrameProcessor {
CountDownLatch* barrier);
void ProcessUpgradeFailureEvent(
ClientProxy* client, const std::string& endpoint_id,
const UpgradePathInfo& upgrade_info,
const location::nearby::connections::BandwidthUpgradeNegotiationFrame::
UpgradePathInfo& upgrade_info,
location::nearby::proto::connections::BandwidthUpgradeResult result,
bool record_analytic,
location::nearby::proto::connections::OperationResultCode
@@ -48,8 +48,6 @@ namespace connections {
namespace {
using ::location::nearby::analytics::proto::ConnectionsLog;
using ::location::nearby::connections::BandwidthUpgradeNegotiationFrame;
using ::location::nearby::connections::
BandwidthUpgradeNegotiationFrame_UpgradePathInfo;
using ::location::nearby::connections::MediumRole;
using ::location::nearby::connections::OfflineFrame;
using ::location::nearby::connections::OsInfo;
@@ -856,8 +854,8 @@ TEST_F(BwuManagerTest, InitiateBwu_Revert_OnUpgradeFailure_FlagEnabled) {
/*initialize_call_index=*/2u, bwu_manager_.get());
// This upgrade fails.
BwuHandler::UpgradePathInfo info;
info.set_medium(BwuHandler::UpgradePathInfo::WEB_RTC);
BandwidthUpgradeNegotiationFrame::UpgradePathInfo info;
info.set_medium(BandwidthUpgradeNegotiationFrame::UpgradePathInfo::WEB_RTC);
ExceptionOr<OfflineFrame> upgrade_failure =
parser::FromBytes(parser::ForBwuFailure(info));
bwu_manager_->OnIncomingFrame(upgrade_failure.result(),
@@ -894,8 +892,8 @@ TEST_F(BwuManagerTest, InitiateBwu_Revert_OnUpgradeFailure_FlagDisabled) {
/*initialize_call_index=*/2u, bwu_manager_.get());
// This upgrade fails.
BwuHandler::UpgradePathInfo info;
info.set_medium(BwuHandler::UpgradePathInfo::WEB_RTC);
BandwidthUpgradeNegotiationFrame::UpgradePathInfo info;
info.set_medium(BandwidthUpgradeNegotiationFrame::UpgradePathInfo::WEB_RTC);
ExceptionOr<OfflineFrame> upgrade_failure =
parser::FromBytes(parser::ForBwuFailure(info));
bwu_manager_->OnIncomingFrame(upgrade_failure.result(),
@@ -925,7 +923,7 @@ TEST_F(BwuManagerTest, InitiateBwu_Revert_OnDisconnect_WifiDirect) {
::nearby::connections::V1Frame* v1_frame = frame.mutable_v1();
::nearby::connections::BandwidthUpgradeNegotiationFrame* sub_frame =
v1_frame->mutable_bandwidth_upgrade_negotiation();
::nearby::connections::BandwidthUpgradeNegotiationFrame_UpgradePathInfo*
BandwidthUpgradeNegotiationFrame::UpgradePathInfo*
upgrade_path_info = sub_frame->mutable_upgrade_path_info();
upgrade_path_info->set_supports_client_introduction_ack(false);
bwu_manager_->OnIncomingFrame(frame, std::string(kEndpointId1), &client_,
@@ -32,6 +32,7 @@
#include "internal/platform/byte_array.h"
#include "internal/platform/exception.h"
#include "internal/platform/expected.h"
#include "internal/platform/logging.h"
#include "internal/platform/mac_address.h"
namespace nearby {
@@ -115,7 +116,8 @@ class FakeBwuHandler : public BaseBwuHandler {
ErrorOr<std::unique_ptr<EndpointChannel>> CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info) final {
const location::nearby::connections::BandwidthUpgradeNegotiationFrame::
UpgradePathInfo& upgrade_path_info) final {
create_calls_.push_back({.client = client,
.service_id = service_id,
.endpoint_id = endpoint_id});
@@ -21,7 +21,6 @@
#include <utility>
#include "absl/functional/bind_front.h"
#include "absl/strings/str_cat.h"
#include "connections/implementation/base_bwu_handler.h"
#include "connections/implementation/client_proxy.h"
#include "connections/implementation/endpoint_channel.h"
@@ -39,6 +38,7 @@ namespace nearby {
namespace connections {
namespace {
using ::location::nearby::connections::BandwidthUpgradeNegotiationFrame;
using ::location::nearby::connections::LocationHint;
using ::location::nearby::connections::LocationStandard;
using ::location::nearby::proto::connections::OperationResultCode;
@@ -78,9 +78,11 @@ WebrtcBwuHandler::WebrtcBwuHandler(
ErrorOr<std::unique_ptr<EndpointChannel>>
WebrtcBwuHandler::CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id, const UpgradePathInfo& upgrade_path_info) {
const UpgradePathInfo::WebRtcCredentials& web_rtc_credentials =
upgrade_path_info.web_rtc_credentials();
const std::string& endpoint_id,
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo&
upgrade_path_info) {
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo::WebRtcCredentials&
web_rtc_credentials = upgrade_path_info.web_rtc_credentials();
mediums::WebrtcPeerId peer_id(web_rtc_credentials.peer_id());
LocationHint location_hint;
@@ -19,7 +19,6 @@
#include <memory>
#include <string>
#include <utility>
#include "connections/implementation/base_bwu_handler.h"
#include "connections/implementation/bwu_handler.h"
@@ -58,11 +57,11 @@ class WebrtcBwuHandler : public BaseBwuHandler {
};
// BwuHandler implementation:
ErrorOr<std::unique_ptr<EndpointChannel>>
CreateUpgradedEndpointChannel(ClientProxy* client,
const std::string& service_id,
const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info) final;
ErrorOr<std::unique_ptr<EndpointChannel>> CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id,
const location::nearby::connections::BandwidthUpgradeNegotiationFrame::
UpgradePathInfo& upgrade_path_info) final;
location::nearby::proto::connections::Medium GetUpgradeMedium() const final {
return Medium::WEB_RTC;
}
@@ -31,6 +31,7 @@ namespace nearby {
namespace connections {
namespace {
using ::location::nearby::connections::BandwidthUpgradeNegotiationFrame;
using ::location::nearby::proto::connections::OperationResultCode;
} // namespace
@@ -52,7 +53,9 @@ WebrtcBwuHandler::WebrtcBwuHandler(
ErrorOr<std::unique_ptr<EndpointChannel>>
WebrtcBwuHandler::CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id, const UpgradePathInfo& upgrade_path_info) {
const std::string& endpoint_id,
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo&
upgrade_path_info) {
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
}
@@ -56,11 +56,11 @@ class WebrtcBwuHandler : public BaseBwuHandler {
};
// BwuHandler implementation:
ErrorOr<std::unique_ptr<EndpointChannel>>
CreateUpgradedEndpointChannel(ClientProxy* client,
const std::string& service_id,
const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info) final;
ErrorOr<std::unique_ptr<EndpointChannel>> CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id,
const location::nearby::connections::BandwidthUpgradeNegotiationFrame::
UpgradePathInfo& upgrade_path_info) final;
location::nearby::proto::connections::Medium GetUpgradeMedium() const final {
return Medium::WEB_RTC;
}
@@ -38,6 +38,7 @@ namespace nearby {
namespace connections {
namespace {
using ::location::nearby::connections::BandwidthUpgradeNegotiationFrame;
using ::location::nearby::proto::connections::OperationResultCode;
} // namespace
@@ -109,14 +110,17 @@ void WifiDirectBwuHandler::HandleRevertInitiatorStateForService(
ErrorOr<std::unique_ptr<EndpointChannel>>
WifiDirectBwuHandler::CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id, const UpgradePathInfo& upgrade_path_info) {
const std::string& endpoint_id,
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo&
upgrade_path_info) {
if (!upgrade_path_info.has_wifi_direct_credentials()) {
LOG(INFO) << "No WifiDirect Credential";
return {Error(
OperationResultCode::CONNECTIVITY_WIFI_DIRECT_INVALID_CREDENTIAL)};
}
const UpgradePathInfo::WifiDirectCredentials& upgrade_path_info_credentials =
upgrade_path_info.wifi_direct_credentials();
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo::
WifiDirectCredentials& upgrade_path_info_credentials =
upgrade_path_info.wifi_direct_credentials();
const std::string& ssid = upgrade_path_info_credentials.ssid();
const std::string& password = upgrade_path_info_credentials.password();
@@ -61,11 +61,11 @@ class WifiDirectBwuHandler : public BaseBwuHandler {
// WFD protocol to established connection while WINRT follow the standard WFD
// spec to achieve the connection. So return fail to stop the upgrade request
// from phone side.
ErrorOr<std::unique_ptr<EndpointChannel>>
CreateUpgradedEndpointChannel(ClientProxy* client,
const std::string& service_id,
const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info) final;
ErrorOr<std::unique_ptr<EndpointChannel>> CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id,
const location::nearby::connections::BandwidthUpgradeNegotiationFrame::
UpgradePathInfo& upgrade_path_info) final;
location::nearby::proto::connections::Medium GetUpgradeMedium() const final {
return location::nearby::proto::connections::Medium::WIFI_DIRECT;
}
@@ -15,9 +15,9 @@
#include "connections/implementation/wifi_hotspot_bwu_handler.h"
#if !defined(_WIN32)
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#endif
#include <cstdint>
@@ -60,8 +60,7 @@ std::vector<char> GatewayToAddressBytes(const std::string& gateway) {
return address_bytes;
}
address_bytes.resize(4);
std::memcpy(address_bytes.data(),
reinterpret_cast<char*>(&address_int), 4);
std::memcpy(address_bytes.data(), reinterpret_cast<char*>(&address_int), 4);
return address_bytes;
}
} // namespace
@@ -163,14 +162,17 @@ void WifiHotspotBwuHandler::HandleRevertInitiatorStateForService(
ErrorOr<std::unique_ptr<EndpointChannel>>
WifiHotspotBwuHandler::CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id, const UpgradePathInfo& upgrade_path_info) {
const std::string& endpoint_id,
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo&
upgrade_path_info) {
if (!upgrade_path_info.has_wifi_hotspot_credentials()) {
LOG(INFO) << "No Hotspot Credential";
return {Error(
OperationResultCode::CONNECTIVITY_WIFI_HOTSPOT_INVALID_CREDENTIAL)};
}
const UpgradePathInfo::WifiHotspotCredentials& upgrade_path_info_credentials =
upgrade_path_info.wifi_hotspot_credentials();
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo::
WifiHotspotCredentials& upgrade_path_info_credentials =
upgrade_path_info.wifi_hotspot_credentials();
HotspotCredentials hotspot_credentials;
hotspot_credentials.SetSSID(upgrade_path_info_credentials.ssid());
@@ -17,7 +17,6 @@
#include <memory>
#include <string>
#include <utility>
#include "connections/implementation/base_bwu_handler.h"
#include "connections/implementation/bwu_handler.h"
@@ -40,6 +39,19 @@ class WifiHotspotBwuHandler : public BaseBwuHandler {
Mediums& mediums,
IncomingConnectionCallback incoming_connection_callback);
// BwuHandler implementation:
ErrorOr<std::unique_ptr<EndpointChannel>> CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id,
const location::nearby::connections::BandwidthUpgradeNegotiationFrame::
UpgradePathInfo& upgrade_path_info) override;
location::nearby::proto::connections::Medium GetUpgradeMedium()
const override {
return location::nearby::proto::connections::Medium::WIFI_HOTSPOT;
}
void OnEndpointDisconnect(ClientProxy* client,
const std::string& endpoint_id) override {}
private:
class WifiHotspotIncomingSocket : public BwuHandler::IncomingSocket {
public:
@@ -55,18 +67,6 @@ class WifiHotspotBwuHandler : public BaseBwuHandler {
WifiHotspotSocket socket_;
};
// BwuHandler implementation:
ErrorOr<std::unique_ptr<EndpointChannel>>
CreateUpgradedEndpointChannel(ClientProxy* client,
const std::string& service_id,
const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info) final;
location::nearby::proto::connections::Medium GetUpgradeMedium() const final {
return location::nearby::proto::connections::Medium::WIFI_HOTSPOT;
}
void OnEndpointDisconnect(ClientProxy* client,
const std::string& endpoint_id) final {}
// BaseBwuHandler implementation:
ByteArray HandleInitializeUpgradedMediumForEndpoint(
ClientProxy* client, const std::string& upgrade_service_id,
@@ -38,6 +38,7 @@ namespace nearby {
namespace connections {
namespace {
using ::location::nearby::connections::BandwidthUpgradeNegotiationFrame;
using ::location::nearby::proto::connections::OperationResultCode;
} // namespace
@@ -51,13 +52,15 @@ WifiLanBwuHandler::WifiLanBwuHandler(
ErrorOr<std::unique_ptr<EndpointChannel>>
WifiLanBwuHandler::CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id, const UpgradePathInfo& upgrade_path_info) {
const std::string& endpoint_id,
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo&
upgrade_path_info) {
if (!upgrade_path_info.has_wifi_lan_socket()) {
return {
Error(OperationResultCode::CONNECTIVITY_WIFI_LAN_INVALID_CREDENTIAL)};
}
const UpgradePathInfo::WifiLanSocket& upgrade_path_info_socket =
upgrade_path_info.wifi_lan_socket();
const BandwidthUpgradeNegotiationFrame::UpgradePathInfo::WifiLanSocket&
upgrade_path_info_socket = upgrade_path_info.wifi_lan_socket();
if ((!upgrade_path_info_socket.has_ip_address() ||
!upgrade_path_info_socket.has_wifi_port()) &&
upgrade_path_info_socket.address_candidates_size() == 0) {
@@ -70,9 +73,8 @@ WifiLanBwuHandler::CreateUpgradedEndpointChannel(
upgrade_path_info_socket.address_candidates()) {
if (address_candidate.has_ip_address() && address_candidate.has_port()) {
address_candidates.push_back(ServiceAddress{
.address =
std::vector<char>(address_candidate.ip_address().begin(),
address_candidate.ip_address().end()),
.address = std::vector<char>(address_candidate.ip_address().begin(),
address_candidate.ip_address().end()),
.port = static_cast<uint16_t>(address_candidate.port())});
}
}
@@ -150,8 +152,7 @@ ByteArray WifiLanBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
if (ip_addresses.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.";
<< endpoint_id << " because there are no available ip addresses.";
return {};
}
return parser::ForBwuWifiLanPathAvailable(ip_addresses, port);
@@ -17,7 +17,6 @@
#include <memory>
#include <string>
#include <utility>
#include "connections/implementation/base_bwu_handler.h"
#include "connections/implementation/bwu_handler.h"
@@ -40,6 +39,19 @@ class WifiLanBwuHandler : public BaseBwuHandler {
Mediums& mediums,
IncomingConnectionCallback incoming_connection_callback);
// BwuHandler implementation:
ErrorOr<std::unique_ptr<EndpointChannel>> CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id,
const location::nearby::connections::BandwidthUpgradeNegotiationFrame::
UpgradePathInfo& upgrade_path_info) override;
location::nearby::proto::connections::Medium GetUpgradeMedium()
const override {
return location::nearby::proto::connections::Medium::WIFI_LAN;
}
void OnEndpointDisconnect(ClientProxy* client,
const std::string& endpoint_id) override {}
private:
class WifiLanIncomingSocket : public BwuHandler::IncomingSocket {
public:
@@ -55,18 +67,6 @@ class WifiLanBwuHandler : public BaseBwuHandler {
WifiLanSocket socket_;
};
// BwuHandler implementation:
ErrorOr<std::unique_ptr<EndpointChannel>>
CreateUpgradedEndpointChannel(ClientProxy* client,
const std::string& service_id,
const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info) final;
location::nearby::proto::connections::Medium GetUpgradeMedium() const final {
return location::nearby::proto::connections::Medium::WIFI_LAN;
}
void OnEndpointDisconnect(ClientProxy* client,
const std::string& endpoint_id) final {}
// BaseBwuHandler implementation:
ByteArray HandleInitializeUpgradedMediumForEndpoint(
ClientProxy* client, const std::string& upgrade_service_id,