From ee1a46c3da44221eed208925ca695c7ccd778512 Mon Sep 17 00:00:00 2001 From: Francis Tsui Date: Wed, 12 Nov 2025 17:35:51 -0800 Subject: [PATCH] Fix code style. PiperOrigin-RevId: 831606257 --- .../implementation/awdl_bwu_handler.cc | 9 ++-- connections/implementation/awdl_bwu_handler.h | 3 +- .../implementation/base_bwu_handler.cc | 3 ++ connections/implementation/base_bwu_handler.h | 5 ++- .../implementation/base_bwu_handler_test.cc | 8 ++-- .../implementation/bluetooth_bwu_handler.cc | 9 ++-- .../implementation/bluetooth_bwu_handler.h | 11 +++-- connections/implementation/bwu_handler.h | 15 +++---- connections/implementation/bwu_manager.cc | 45 +++++++++++-------- connections/implementation/bwu_manager.h | 43 ++++++++++-------- .../implementation/bwu_manager_test.cc | 12 +++-- connections/implementation/fake_bwu_handler.h | 4 +- .../implementation/webrtc_bwu_handler.cc | 10 +++-- .../implementation/webrtc_bwu_handler.h | 11 +++-- .../implementation/webrtc_bwu_handler_stub.cc | 5 ++- .../implementation/webrtc_bwu_handler_stub.h | 10 ++--- .../implementation/wifi_direct_bwu_handler.cc | 10 +++-- .../implementation/wifi_direct_bwu_handler.h | 10 ++--- .../wifi_hotspot_bwu_handler.cc | 16 ++++--- .../implementation/wifi_hotspot_bwu_handler.h | 26 +++++------ .../implementation/wifi_lan_bwu_handler.cc | 17 +++---- .../implementation/wifi_lan_bwu_handler.h | 26 +++++------ 22 files changed, 169 insertions(+), 139 deletions(-) diff --git a/connections/implementation/awdl_bwu_handler.cc b/connections/implementation/awdl_bwu_handler.cc index 9f710573..45baead2 100644 --- a/connections/implementation/awdl_bwu_handler.cc +++ b/connections/implementation/awdl_bwu_handler.cc @@ -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> 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()) { diff --git a/connections/implementation/awdl_bwu_handler.h b/connections/implementation/awdl_bwu_handler.h index 3ab87910..25e921ec 100644 --- a/connections/implementation/awdl_bwu_handler.h +++ b/connections/implementation/awdl_bwu_handler.h @@ -59,7 +59,8 @@ class AwdlBwuHandler : public BaseBwuHandler { ErrorOr> 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; } diff --git a/connections/implementation/base_bwu_handler.cc b/connections/implementation/base_bwu_handler.cc index 3242976c..15f14aa2 100644 --- a/connections/implementation/base_bwu_handler.cc +++ b/connections/implementation/base_bwu_handler.cc @@ -14,10 +14,13 @@ #include "connections/implementation/base_bwu_handler.h" +#include #include #include +#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 { diff --git a/connections/implementation/base_bwu_handler.h b/connections/implementation/base_bwu_handler.h index 783d90e4..3f8e40ad 100644 --- a/connections/implementation/base_bwu_handler.h +++ b/connections/implementation/base_bwu_handler.h @@ -19,9 +19,10 @@ #include #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 { diff --git a/connections/implementation/base_bwu_handler_test.cc b/connections/implementation/base_bwu_handler_test.cc index b87c8d5b..da3f87ab 100644 --- a/connections/implementation/base_bwu_handler_test.cc +++ b/connections/implementation/base_bwu_handler_test.cc @@ -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> - CreateUpgradedEndpointChannel( + ErrorOr> 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; } diff --git a/connections/implementation/bluetooth_bwu_handler.cc b/connections/implementation/bluetooth_bwu_handler.cc index 94f230fb..f6734597 100644 --- a/connections/implementation/bluetooth_bwu_handler.cc +++ b/connections/implementation/bluetooth_bwu_handler.cc @@ -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> 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."; diff --git a/connections/implementation/bluetooth_bwu_handler.h b/connections/implementation/bluetooth_bwu_handler.h index 46466ee2..ae409310 100644 --- a/connections/implementation/bluetooth_bwu_handler.h +++ b/connections/implementation/bluetooth_bwu_handler.h @@ -17,7 +17,6 @@ #include #include -#include #include "connections/implementation/base_bwu_handler.h" #include "connections/implementation/client_proxy.h" @@ -57,11 +56,11 @@ class BluetoothBwuHandler : public BaseBwuHandler { }; // BwuHandler implementation: - ErrorOr> - CreateUpgradedEndpointChannel(ClientProxy* client, - const std::string& service_id, - const std::string& endpoint_id, - const UpgradePathInfo& upgrade_path_info) final; + ErrorOr> 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 {} diff --git a/connections/implementation/bwu_handler.h b/connections/implementation/bwu_handler.h index 0deb84bc..cd0fc073 100644 --- a/connections/implementation/bwu_handler.h +++ b/connections/implementation/bwu_handler.h @@ -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> - 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 diff --git a/connections/implementation/bwu_manager.cc b/connections/implementation/bwu_manager.cc index 14c87503..8c4521ab 100644 --- a/connections/implementation/bwu_manager.cc +++ b/connections/implementation/bwu_manager.cc @@ -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> 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( diff --git a/connections/implementation/bwu_manager.h b/connections/implementation/bwu_manager.h index 15e66f4e..2c5c766c 100644 --- a/connections/implementation/bwu_manager.h +++ b/connections/implementation/bwu_manager.h @@ -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& 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 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> 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 diff --git a/connections/implementation/bwu_manager_test.cc b/connections/implementation/bwu_manager_test.cc index 3d4d21ef..c9e75345 100644 --- a/connections/implementation/bwu_manager_test.cc +++ b/connections/implementation/bwu_manager_test.cc @@ -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 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 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_, diff --git a/connections/implementation/fake_bwu_handler.h b/connections/implementation/fake_bwu_handler.h index e17fb876..4381f75c 100644 --- a/connections/implementation/fake_bwu_handler.h +++ b/connections/implementation/fake_bwu_handler.h @@ -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> 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}); diff --git a/connections/implementation/webrtc_bwu_handler.cc b/connections/implementation/webrtc_bwu_handler.cc index b611cf88..6f1d07ce 100644 --- a/connections/implementation/webrtc_bwu_handler.cc +++ b/connections/implementation/webrtc_bwu_handler.cc @@ -21,7 +21,6 @@ #include #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> 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; diff --git a/connections/implementation/webrtc_bwu_handler.h b/connections/implementation/webrtc_bwu_handler.h index 8ad821b8..c865420e 100644 --- a/connections/implementation/webrtc_bwu_handler.h +++ b/connections/implementation/webrtc_bwu_handler.h @@ -19,7 +19,6 @@ #include #include -#include #include "connections/implementation/base_bwu_handler.h" #include "connections/implementation/bwu_handler.h" @@ -58,11 +57,11 @@ class WebrtcBwuHandler : public BaseBwuHandler { }; // BwuHandler implementation: - ErrorOr> - CreateUpgradedEndpointChannel(ClientProxy* client, - const std::string& service_id, - const std::string& endpoint_id, - const UpgradePathInfo& upgrade_path_info) final; + ErrorOr> 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; } diff --git a/connections/implementation/webrtc_bwu_handler_stub.cc b/connections/implementation/webrtc_bwu_handler_stub.cc index 4bbb292f..1b37f9e3 100644 --- a/connections/implementation/webrtc_bwu_handler_stub.cc +++ b/connections/implementation/webrtc_bwu_handler_stub.cc @@ -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> 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)}; } diff --git a/connections/implementation/webrtc_bwu_handler_stub.h b/connections/implementation/webrtc_bwu_handler_stub.h index e3b0aebb..f20b4898 100644 --- a/connections/implementation/webrtc_bwu_handler_stub.h +++ b/connections/implementation/webrtc_bwu_handler_stub.h @@ -56,11 +56,11 @@ class WebrtcBwuHandler : public BaseBwuHandler { }; // BwuHandler implementation: - ErrorOr> - CreateUpgradedEndpointChannel(ClientProxy* client, - const std::string& service_id, - const std::string& endpoint_id, - const UpgradePathInfo& upgrade_path_info) final; + ErrorOr> 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; } diff --git a/connections/implementation/wifi_direct_bwu_handler.cc b/connections/implementation/wifi_direct_bwu_handler.cc index 417eae3f..a015bb7e 100644 --- a/connections/implementation/wifi_direct_bwu_handler.cc +++ b/connections/implementation/wifi_direct_bwu_handler.cc @@ -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> 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(); diff --git a/connections/implementation/wifi_direct_bwu_handler.h b/connections/implementation/wifi_direct_bwu_handler.h index c189b87d..242704dd 100644 --- a/connections/implementation/wifi_direct_bwu_handler.h +++ b/connections/implementation/wifi_direct_bwu_handler.h @@ -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> - CreateUpgradedEndpointChannel(ClientProxy* client, - const std::string& service_id, - const std::string& endpoint_id, - const UpgradePathInfo& upgrade_path_info) final; + ErrorOr> 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; } diff --git a/connections/implementation/wifi_hotspot_bwu_handler.cc b/connections/implementation/wifi_hotspot_bwu_handler.cc index 49eb5ca0..123a8d6f 100644 --- a/connections/implementation/wifi_hotspot_bwu_handler.cc +++ b/connections/implementation/wifi_hotspot_bwu_handler.cc @@ -15,9 +15,9 @@ #include "connections/implementation/wifi_hotspot_bwu_handler.h" #if !defined(_WIN32) -#include -#include #include +#include +#include #endif #include @@ -60,8 +60,7 @@ std::vector GatewayToAddressBytes(const std::string& gateway) { return address_bytes; } address_bytes.resize(4); - std::memcpy(address_bytes.data(), - reinterpret_cast(&address_int), 4); + std::memcpy(address_bytes.data(), reinterpret_cast(&address_int), 4); return address_bytes; } } // namespace @@ -163,14 +162,17 @@ void WifiHotspotBwuHandler::HandleRevertInitiatorStateForService( ErrorOr> 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()); diff --git a/connections/implementation/wifi_hotspot_bwu_handler.h b/connections/implementation/wifi_hotspot_bwu_handler.h index f19f708d..a21705b9 100644 --- a/connections/implementation/wifi_hotspot_bwu_handler.h +++ b/connections/implementation/wifi_hotspot_bwu_handler.h @@ -17,7 +17,6 @@ #include #include -#include #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> 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> - 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, diff --git a/connections/implementation/wifi_lan_bwu_handler.cc b/connections/implementation/wifi_lan_bwu_handler.cc index 0cbd42cd..0d99ba8c 100644 --- a/connections/implementation/wifi_lan_bwu_handler.cc +++ b/connections/implementation/wifi_lan_bwu_handler.cc @@ -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> 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(address_candidate.ip_address().begin(), - address_candidate.ip_address().end()), + .address = std::vector(address_candidate.ip_address().begin(), + address_candidate.ip_address().end()), .port = static_cast(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); diff --git a/connections/implementation/wifi_lan_bwu_handler.h b/connections/implementation/wifi_lan_bwu_handler.h index 64bad310..2e00bf79 100644 --- a/connections/implementation/wifi_lan_bwu_handler.h +++ b/connections/implementation/wifi_lan_bwu_handler.h @@ -17,7 +17,6 @@ #include #include -#include #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> 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> - 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,