mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
analytics: Update the returned code for CreateUpgradedEndpointChannel of BWUHanlder and its enherited class for NC mediums.
PiperOrigin-RevId: 704171725
This commit is contained in:
committed by
Copybara-Service
parent
c3a479e526
commit
d7a1fb8c48
@@ -14,18 +14,27 @@
|
||||
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/service_id_constants.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
namespace {
|
||||
|
||||
// Because BaseBwuHandler is still an abstract class, we need to implement the
|
||||
// pure virtual functions in order to test BaseBwuHandler's bookkeeping logic.
|
||||
using ::location::nearby::proto::connections::OperationResultCode;
|
||||
|
||||
// Because BaseBwuHandler is still an abstract class, we need to implement the
|
||||
// pure virtual functions in order to test BaseBwuHandler's bookkeeping logic.
|
||||
class BwuHandlerImpl : public BaseBwuHandler {
|
||||
public:
|
||||
using Medium = ::location::nearby::proto::connections::Medium;
|
||||
@@ -34,8 +43,8 @@ class BwuHandlerImpl : public BaseBwuHandler {
|
||||
// for every method.
|
||||
struct InputData {
|
||||
ClientProxy* client = nullptr;
|
||||
absl::optional<std::string> service_id;
|
||||
absl::optional<std::string> endpoint_id;
|
||||
std::optional<std::string> service_id;
|
||||
std::optional<std::string> endpoint_id;
|
||||
};
|
||||
|
||||
BwuHandlerImpl() : BaseBwuHandler(nullptr) {}
|
||||
@@ -52,11 +61,12 @@ class BwuHandlerImpl : public BaseBwuHandler {
|
||||
|
||||
private:
|
||||
// BwuHandler implementation:
|
||||
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 {
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
Medium GetUpgradeMedium() const final { return Medium::UNKNOWN_MEDIUM; }
|
||||
void OnEndpointDisconnect(ClientProxy* client,
|
||||
|
||||
@@ -14,13 +14,21 @@
|
||||
|
||||
#include "connections/implementation/bluetooth_bwu_handler.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/functional/bind_front.h"
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/bluetooth_endpoint_channel.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "internal/platform/bluetooth_adapter.h"
|
||||
#include "internal/platform/bluetooth_classic.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
// Manages the Bluetooth-specific methods needed to upgrade an {@link
|
||||
@@ -29,6 +37,11 @@
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
namespace {
|
||||
using ::location::nearby::proto::connections::OperationResultCode;
|
||||
} // namespace
|
||||
|
||||
// TODO(edwinwu): Add exact OperationResultCode for BluetoothBwuHandler.
|
||||
BluetoothBwuHandler::BluetoothBwuHandler(
|
||||
Mediums& mediums, IncomingConnectionCallback incoming_connection_callback)
|
||||
: BaseBwuHandler(std::move(incoming_connection_callback)),
|
||||
@@ -37,7 +50,7 @@ BluetoothBwuHandler::BluetoothBwuHandler(
|
||||
// Called by BWU target. Retrieves a new medium info from incoming message,
|
||||
// and establishes connection over BT using this info.
|
||||
// Returns a channel ready to exchange data or nullptr on error.
|
||||
std::unique_ptr<EndpointChannel>
|
||||
ErrorOr<std::unique_ptr<EndpointChannel>>
|
||||
BluetoothBwuHandler::CreateUpgradedEndpointChannel(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id, const UpgradePathInfo& upgrade_path_info) {
|
||||
@@ -47,7 +60,7 @@ BluetoothBwuHandler::CreateUpgradedEndpointChannel(
|
||||
!bluetooth_credentials.has_mac_address()) {
|
||||
NEARBY_LOGS(ERROR)
|
||||
<< "BluetoothBwuHandler failed to parse UpgradePathInfo.";
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
const std::string& service_name = bluetooth_credentials.service_name();
|
||||
@@ -64,7 +77,7 @@ BluetoothBwuHandler::CreateUpgradedEndpointChannel(
|
||||
<< "BluetoothBwuHandler failed to derive a valid Bluetooth device "
|
||||
"from the MAC address ("
|
||||
<< mac_address << ") for endpoint " << endpoint_id;
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
BluetoothSocket socket = bluetooth_medium_.Connect(
|
||||
@@ -74,7 +87,7 @@ BluetoothBwuHandler::CreateUpgradedEndpointChannel(
|
||||
<< "BluetoothBwuHandler failed to connect to the Bluetooth device ("
|
||||
<< service_name << ", " << mac_address << ") for endpoint "
|
||||
<< endpoint_id << " and service ID " << service_id;
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
NEARBY_VLOG(1)
|
||||
@@ -91,11 +104,11 @@ BluetoothBwuHandler::CreateUpgradedEndpointChannel(
|
||||
<< service_name << ", " << mac_address << ") for endpoint "
|
||||
<< endpoint_id << " and service ID " << service_id;
|
||||
socket.Close();
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
client->SetBluetoothMacAddress(endpoint_id, mac_address);
|
||||
return channel;
|
||||
return {std::move(channel)};
|
||||
}
|
||||
|
||||
ByteArray BluetoothBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
@@ -146,7 +159,7 @@ void BluetoothBwuHandler::HandleRevertInitiatorStateForService(
|
||||
void BluetoothBwuHandler::OnIncomingBluetoothConnection(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
BluetoothSocket socket) {
|
||||
auto channel = absl::make_unique<BluetoothEndpointChannel>(
|
||||
auto channel = std::make_unique<BluetoothEndpointChannel>(
|
||||
upgrade_service_id, /*channel_name=*/upgrade_service_id, socket);
|
||||
std::unique_ptr<IncomingSocketConnection> connection{
|
||||
new IncomingSocketConnection{
|
||||
|
||||
@@ -15,14 +15,20 @@
|
||||
#ifndef CORE_INTERNAL_BLUETOOTH_BWU_HANDLER_H_
|
||||
#define CORE_INTERNAL_BLUETOOTH_BWU_HANDLER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/bluetooth_classic.h"
|
||||
#include "connections/implementation/mediums/bluetooth_radio.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/mediums/utils.h"
|
||||
#include "connections/medium_selector.h"
|
||||
#include "internal/platform/bluetooth_classic.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -51,10 +57,11 @@ class BluetoothBwuHandler : public BaseBwuHandler {
|
||||
};
|
||||
|
||||
// BwuHandler implementation:
|
||||
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 UpgradePathInfo& upgrade_path_info) final;
|
||||
Medium GetUpgradeMedium() const final { return Medium::BLUETOOTH; }
|
||||
void OnEndpointDisconnect(ClientProxy* client,
|
||||
const std::string& endpoint_id) final {}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/time/time.h"
|
||||
@@ -25,6 +26,7 @@
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/feature_flags.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
@@ -35,6 +37,7 @@ namespace connections {
|
||||
|
||||
namespace {
|
||||
using ::location::nearby::connections::OfflineFrame;
|
||||
using ::location::nearby::proto::connections::OperationResultCode;
|
||||
constexpr absl::Duration kWaitDuration = absl::Milliseconds(1000);
|
||||
} // namespace
|
||||
|
||||
@@ -101,17 +104,22 @@ TEST_F(BluetoothBwuTest, SoftAPBWUInit_STACreateEndpointChannel) {
|
||||
auto bwu_frame =
|
||||
upgrade_frame.result().v1().bandwidth_upgrade_negotiation();
|
||||
|
||||
std::unique_ptr<EndpointChannel> new_channel =
|
||||
ErrorOr<std::unique_ptr<EndpointChannel>> result =
|
||||
handler_2->CreateUpgradedEndpointChannel(&client_2, /*service_id=*/"A",
|
||||
/*endpoint_id=*/"1",
|
||||
bwu_frame.upgrade_path_info());
|
||||
if (!FeatureFlags::GetInstance().GetFlags().enable_cancellation_flag) {
|
||||
ASSERT_TRUE(result.has_value());
|
||||
std::unique_ptr<EndpointChannel> new_channel = std::move(result.value());
|
||||
EXPECT_TRUE(accept_latch.Await(kWaitDuration).result());
|
||||
EXPECT_EQ(new_channel->GetMedium(),
|
||||
location::nearby::proto::connections::Medium::BLUETOOTH);
|
||||
} else {
|
||||
EXPECT_FALSE(result.has_value());
|
||||
EXPECT_TRUE(result.has_error());
|
||||
EXPECT_EQ(result.error().operation_result_code(),
|
||||
OperationResultCode::DETAIL_UNKNOWN);
|
||||
accept_latch.CountDown();
|
||||
EXPECT_EQ(new_channel, nullptr);
|
||||
}
|
||||
EXPECT_FALSE(mediums_2.GetBluetoothClassic().GetMacAddress().empty());
|
||||
handler_2->RevertResponderState(/*service_id=*/"A");
|
||||
|
||||
@@ -15,14 +15,15 @@
|
||||
#ifndef CORE_INTERNAL_BWU_HANDLER_H_
|
||||
#define CORE_INTERNAL_BWU_HANDLER_H_
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#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/count_down_latch.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -81,14 +82,16 @@ class BwuHandler {
|
||||
// that hasn't already been done) using the UpgradePathInfo sent by the
|
||||
// Initiator, and returns a new EndpointChannel for the upgraded medium.
|
||||
// @BwuHandlerThread
|
||||
virtual std::unique_ptr<EndpointChannel> CreateUpgradedEndpointChannel(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id,
|
||||
const UpgradePathInfo& upgrade_path_info) = 0;
|
||||
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;
|
||||
|
||||
// Returns the upgrade medium of the BwuHandler.
|
||||
// @BwuHandlerThread
|
||||
virtual Medium GetUpgradeMedium() const = 0;
|
||||
virtual location::nearby::proto::connections::Medium GetUpgradeMedium()
|
||||
const = 0;
|
||||
|
||||
virtual void OnEndpointDisconnect(ClientProxy* client,
|
||||
const std::string& endpoint_id) = 0;
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/cancelable_alarm.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/feature_flags.h"
|
||||
#include "internal/platform/implementation/system_clock.h"
|
||||
#include "internal/platform/logging.h"
|
||||
@@ -882,10 +883,10 @@ BwuManager::ProcessBwuPathAvailableEventInternal(
|
||||
service_id = old_channel->GetServiceId();
|
||||
}
|
||||
|
||||
std::unique_ptr<EndpointChannel> new_channel =
|
||||
ErrorOr<std::unique_ptr<EndpointChannel>> result =
|
||||
handler->CreateUpgradedEndpointChannel(client, service_id, endpoint_id,
|
||||
upgrade_path_info);
|
||||
if (!new_channel) {
|
||||
if (result.has_error() || !result.has_value()) {
|
||||
NEARBY_LOGS(ERROR) << "BwuManager failed to create an endpoint "
|
||||
"channel to endpoint"
|
||||
<< endpoint_id << ", aborting upgrade.";
|
||||
@@ -894,6 +895,7 @@ BwuManager::ProcessBwuPathAvailableEventInternal(
|
||||
location::nearby::proto::connections::SOCKET_CREATION);
|
||||
return nullptr;
|
||||
}
|
||||
std::unique_ptr<EndpointChannel> new_channel = std::move(result.value());
|
||||
|
||||
// Write the requisite BANDWIDTH_UPGRADE_NEGOTIATION.CLIENT_INTRODUCTION as
|
||||
// the first OfflineFrame on this new EndpointChannel.
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#ifndef NEARBY_CONNECTIONS_IMPLEMENTATION_FAKE_BWU_HANDLER_H_
|
||||
#define NEARBY_CONNECTIONS_IMPLEMENTATION_FAKE_BWU_HANDLER_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -22,9 +23,15 @@
|
||||
#include <vector>
|
||||
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/bwu_manager.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/fake_endpoint_channel.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/expected.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -104,14 +111,15 @@ class FakeBwuHandler : public BaseBwuHandler {
|
||||
};
|
||||
|
||||
// BwuHandler:
|
||||
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 {
|
||||
create_calls_.push_back({.client = client,
|
||||
.service_id = service_id,
|
||||
.endpoint_id = endpoint_id});
|
||||
return std::make_unique<FakeEndpointChannel>(medium_, service_id);
|
||||
return {std::make_unique<FakeEndpointChannel>(medium_, service_id)};
|
||||
}
|
||||
|
||||
Medium GetUpgradeMedium() const final { return medium_; }
|
||||
|
||||
@@ -32,13 +32,19 @@
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "connections/implementation/webrtc_endpoint_channel.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
namespace {
|
||||
using ::location::nearby::connections::LocationHint;
|
||||
using ::location::nearby::connections::LocationStandard;
|
||||
using ::location::nearby::proto::connections::OperationResultCode;
|
||||
} // namespace
|
||||
|
||||
// TODO(edwinwu): Add exact OperationResultCode for WebrtcBwuHandler.
|
||||
WebrtcBwuHandler::WebrtcIncomingSocket::WebrtcIncomingSocket(
|
||||
const std::string& name, mediums::WebRtcSocketWrapper socket)
|
||||
: name_(name), socket_(socket) {}
|
||||
@@ -54,7 +60,7 @@ WebrtcBwuHandler::WebrtcBwuHandler(
|
||||
|
||||
// Called by BWU target. Retrieves a new medium info from incoming message,
|
||||
// and establishes connection over WebRTC using this info.
|
||||
std::unique_ptr<EndpointChannel>
|
||||
ErrorOr<std::unique_ptr<EndpointChannel>>
|
||||
WebrtcBwuHandler::CreateUpgradedEndpointChannel(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id, const UpgradePathInfo& upgrade_path_info) {
|
||||
@@ -79,7 +85,7 @@ WebrtcBwuHandler::CreateUpgradedEndpointChannel(
|
||||
NEARBY_LOGS(ERROR) << "WebRtcBwuHandler failed to connect to remote peer ("
|
||||
<< peer_id.GetId() << ") on endpoint " << endpoint_id
|
||||
<< ", aborting upgrade.";
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
NEARBY_LOGS(INFO) << "WebRtcBwuHandler successfully connected to remote "
|
||||
@@ -95,9 +101,10 @@ WebrtcBwuHandler::CreateUpgradedEndpointChannel(
|
||||
NEARBY_LOGS(ERROR)
|
||||
<< "WebRtcBwuHandler failed to create new EndpointChannel for "
|
||||
"outgoing socket, aborting upgrade.";
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
return channel;
|
||||
return {std::move(channel)};
|
||||
}
|
||||
|
||||
void WebrtcBwuHandler::HandleRevertInitiatorStateForService(
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
@@ -29,6 +30,7 @@
|
||||
#include "connections/implementation/mediums/webrtc_socket.h"
|
||||
#include "connections/medium_selector.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -56,11 +58,14 @@ class WebrtcBwuHandler : public BaseBwuHandler {
|
||||
};
|
||||
|
||||
// BwuHandler implementation:
|
||||
std::unique_ptr<EndpointChannel> CreateUpgradedEndpointChannel(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id,
|
||||
const UpgradePathInfo& upgrade_path_info) final;
|
||||
Medium GetUpgradeMedium() const final { return Medium::WEB_RTC; }
|
||||
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 Medium::WEB_RTC;
|
||||
}
|
||||
void OnEndpointDisconnect(ClientProxy* client,
|
||||
const std::string& endpoint_id) final {}
|
||||
|
||||
|
||||
@@ -25,10 +25,15 @@
|
||||
#include "connections/implementation/mediums/webrtc_peer_id_stub.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "connections/implementation/webrtc_endpoint_channel.h"
|
||||
#include "internal/platform/expected.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
namespace {
|
||||
using ::location::nearby::proto::connections::OperationResultCode;
|
||||
} // namespace
|
||||
|
||||
WebrtcBwuHandler::WebrtcIncomingSocket::WebrtcIncomingSocket(
|
||||
const std::string& name, mediums::WebRtcSocketWrapper socket)
|
||||
: name_(name), socket_(socket) {}
|
||||
@@ -44,11 +49,11 @@ WebrtcBwuHandler::WebrtcBwuHandler(
|
||||
|
||||
// Called by BWU target. Retrieves a new medium info from incoming message,
|
||||
// and establishes connection over WebRTC using this info.
|
||||
std::unique_ptr<EndpointChannel>
|
||||
ErrorOr<std::unique_ptr<EndpointChannel>>
|
||||
WebrtcBwuHandler::CreateUpgradedEndpointChannel(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id, const UpgradePathInfo& upgrade_path_info) {
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
void WebrtcBwuHandler::HandleRevertInitiatorStateForService(
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#else
|
||||
#include "connections/implementation/mediums/webrtc_socket.h"
|
||||
#endif
|
||||
#include "internal/platform/expected.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -55,11 +56,14 @@ class WebrtcBwuHandler : public BaseBwuHandler {
|
||||
};
|
||||
|
||||
// BwuHandler implementation:
|
||||
std::unique_ptr<EndpointChannel> CreateUpgradedEndpointChannel(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id,
|
||||
const UpgradePathInfo& upgrade_path_info) final;
|
||||
Medium GetUpgradeMedium() const final { return Medium::WEB_RTC; }
|
||||
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 Medium::WEB_RTC;
|
||||
}
|
||||
void OnEndpointDisconnect(ClientProxy* client,
|
||||
const std::string& endpoint_id) final {}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "connections/implementation/wifi_direct_bwu_handler.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <locale>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -28,6 +27,7 @@
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "connections/implementation/wifi_direct_endpoint_channel.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/wifi_credential.h"
|
||||
#include "internal/platform/wifi_direct.h"
|
||||
@@ -35,6 +35,11 @@
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
namespace {
|
||||
using ::location::nearby::proto::connections::OperationResultCode;
|
||||
} // namespace
|
||||
|
||||
// TODO(edwinwu): Add exact OperationResultCode for WifiDirectBwuHandler.
|
||||
WifiDirectBwuHandler::WifiDirectBwuHandler(
|
||||
Mediums& mediums, IncomingConnectionCallback incoming_connection_callback)
|
||||
: BaseBwuHandler(std::move(incoming_connection_callback)),
|
||||
@@ -101,13 +106,13 @@ void WifiDirectBwuHandler::HandleRevertInitiatorStateForService(
|
||||
<< "upgrade service ID " << upgrade_service_id;
|
||||
}
|
||||
|
||||
std::unique_ptr<EndpointChannel>
|
||||
ErrorOr<std::unique_ptr<EndpointChannel>>
|
||||
WifiDirectBwuHandler::CreateUpgradedEndpointChannel(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id, const UpgradePathInfo& upgrade_path_info) {
|
||||
if (!upgrade_path_info.has_wifi_direct_credentials()) {
|
||||
NEARBY_LOGS(INFO) << "No WifiDirect Credential";
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
const UpgradePathInfo::WifiDirectCredentials& upgrade_path_info_credentials =
|
||||
upgrade_path_info.wifi_direct_credentials();
|
||||
@@ -123,7 +128,7 @@ WifiDirectBwuHandler::CreateUpgradedEndpointChannel(
|
||||
|
||||
if (!wifi_direct_medium_.ConnectWifiDirect(ssid, password)) {
|
||||
NEARBY_LOGS(ERROR) << "Connect to WifiDiret GO failed";
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
WifiDirectSocket socket = wifi_direct_medium_.Connect(
|
||||
@@ -132,7 +137,7 @@ WifiDirectBwuHandler::CreateUpgradedEndpointChannel(
|
||||
NEARBY_LOGS(ERROR)
|
||||
<< "WifiDirectBwuHandler failed to connect to the WifiDirect service("
|
||||
<< port << ") for endpoint " << endpoint_id;
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
NEARBY_VLOG(1)
|
||||
@@ -140,8 +145,8 @@ WifiDirectBwuHandler::CreateUpgradedEndpointChannel(
|
||||
<< port << ") while upgrading endpoint " << endpoint_id;
|
||||
|
||||
// Create a new WifiDirectEndpointChannel.
|
||||
return std::make_unique<WifiDirectEndpointChannel>(
|
||||
service_id, /*channel_name=*/service_id, socket);
|
||||
return {std::make_unique<WifiDirectEndpointChannel>(
|
||||
service_id, /*channel_name=*/service_id, socket)};
|
||||
}
|
||||
|
||||
void WifiDirectBwuHandler::OnIncomingWifiDirectConnection(
|
||||
|
||||
@@ -19,8 +19,16 @@
|
||||
#include <string>
|
||||
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/mediums/wifi.h"
|
||||
#include "connections/implementation/mediums/wifi_direct.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/wifi_direct.h"
|
||||
#include "utility"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -53,11 +61,14 @@ 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.
|
||||
std::unique_ptr<EndpointChannel> CreateUpgradedEndpointChannel(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id,
|
||||
const UpgradePathInfo& upgrade_path_info) final;
|
||||
Medium GetUpgradeMedium() const final { return Medium::WIFI_DIRECT; }
|
||||
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_DIRECT;
|
||||
}
|
||||
void OnEndpointDisconnect(ClientProxy* client,
|
||||
const std::string& endpoint_id) final {}
|
||||
|
||||
|
||||
@@ -16,16 +16,28 @@
|
||||
#include <utility>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "connections/implementation/wifi_direct_bwu_handler.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/feature_flags.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/single_thread_executor.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
namespace {
|
||||
using ::location::nearby::connections::OfflineFrame;
|
||||
using ::location::nearby::proto::connections::OperationResultCode;
|
||||
constexpr absl::Duration kWaitDuration = absl::Milliseconds(1000);
|
||||
} // namespace
|
||||
|
||||
@@ -97,17 +109,22 @@ TEST_F(WifiDirectTest, WFDGOBWUInit_GCCreateEndpointChannel) {
|
||||
auto bwu_frame =
|
||||
upgrade_frame.result().v1().bandwidth_upgrade_negotiation();
|
||||
|
||||
std::unique_ptr<EndpointChannel> new_channel =
|
||||
ErrorOr<std::unique_ptr<EndpointChannel>> result =
|
||||
handler_2->CreateUpgradedEndpointChannel(
|
||||
&wifi_direct_gc, /*service_id=*/"A",
|
||||
/*endpoint_id=*/"1", bwu_frame.upgrade_path_info());
|
||||
if (!FeatureFlags::GetInstance().GetFlags().enable_cancellation_flag) {
|
||||
ASSERT_TRUE(result.has_value());
|
||||
std::unique_ptr<EndpointChannel> new_channel = std::move(result.value());
|
||||
EXPECT_TRUE(accept_latch.Await(kWaitDuration).result());
|
||||
EXPECT_EQ(new_channel->GetMedium(),
|
||||
location::nearby::proto::connections::Medium::WIFI_DIRECT);
|
||||
} else {
|
||||
EXPECT_FALSE(result.has_value());
|
||||
EXPECT_TRUE(result.has_error());
|
||||
EXPECT_EQ(result.error().operation_result_code(),
|
||||
OperationResultCode::DETAIL_UNKNOWN);
|
||||
accept_latch.CountDown();
|
||||
EXPECT_EQ(new_channel, nullptr);
|
||||
}
|
||||
EXPECT_TRUE(mediums_2.GetWifiDirect().IsConnectedToGO());
|
||||
handler_2->RevertResponderState(/*service_id=*/"A");
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "connections/implementation/wifi_hotspot_bwu_handler.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <locale>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -25,11 +24,11 @@
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/mediums/utils.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "connections/implementation/wifi_hotspot_endpoint_channel.h"
|
||||
#include "connections/strategy.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/wifi_credential.h"
|
||||
#include "internal/platform/wifi_hotspot.h"
|
||||
@@ -37,6 +36,11 @@
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
namespace {
|
||||
using ::location::nearby::proto::connections::OperationResultCode;
|
||||
} // namespace
|
||||
|
||||
// TODO(edwinwu): Add exact OperationResultCode for WifiHotspotBwuHandler.
|
||||
WifiHotspotBwuHandler::WifiHotspotBwuHandler(
|
||||
Mediums& mediums, IncomingConnectionCallback incoming_connection_callback)
|
||||
: BaseBwuHandler(std::move(incoming_connection_callback)),
|
||||
@@ -108,13 +112,13 @@ void WifiHotspotBwuHandler::HandleRevertInitiatorStateForService(
|
||||
|
||||
// Called by BWU target. Retrieves a new medium info from incoming message,
|
||||
// and establishes connection over WifiHotspot using this info.
|
||||
std::unique_ptr<EndpointChannel>
|
||||
ErrorOr<std::unique_ptr<EndpointChannel>>
|
||||
WifiHotspotBwuHandler::CreateUpgradedEndpointChannel(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id, const UpgradePathInfo& upgrade_path_info) {
|
||||
if (!upgrade_path_info.has_wifi_hotspot_credentials()) {
|
||||
NEARBY_LOGS(INFO) << "No Hotspot Credential";
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
const UpgradePathInfo::WifiHotspotCredentials& upgrade_path_info_credentials =
|
||||
upgrade_path_info.wifi_hotspot_credentials();
|
||||
@@ -131,7 +135,7 @@ WifiHotspotBwuHandler::CreateUpgradedEndpointChannel(
|
||||
|
||||
if (!wifi_hotspot_medium_.ConnectWifiHotspot(ssid, password, frequency)) {
|
||||
NEARBY_LOGS(ERROR) << "Connect to Hotspot failed";
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
WifiHotspotSocket socket = wifi_hotspot_medium_.Connect(
|
||||
@@ -140,7 +144,7 @@ WifiHotspotBwuHandler::CreateUpgradedEndpointChannel(
|
||||
NEARBY_LOGS(ERROR)
|
||||
<< "WifiHotspotBwuHandler failed to connect to the WifiHotspot service("
|
||||
<< gateway << ":" << port << ") for endpoint " << endpoint_id;
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
NEARBY_VLOG(1)
|
||||
@@ -151,7 +155,7 @@ WifiHotspotBwuHandler::CreateUpgradedEndpointChannel(
|
||||
auto channel = std::make_unique<WifiHotspotEndpointChannel>(
|
||||
service_id, /*channel_name=*/service_id, socket);
|
||||
|
||||
return channel;
|
||||
return {std::move(channel)};
|
||||
}
|
||||
|
||||
// Accept Connection Callback.
|
||||
|
||||
@@ -15,12 +15,19 @@
|
||||
#ifndef CORE_INTERNAL_WIFI_HOTSPOT_BWU_HANDLER_H_
|
||||
#define CORE_INTERNAL_WIFI_HOTSPOT_BWU_HANDLER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel_manager.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/mediums/wifi_hotspot.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/wifi_hotspot.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -49,11 +56,14 @@ class WifiHotspotBwuHandler : public BaseBwuHandler {
|
||||
};
|
||||
|
||||
// BwuHandler implementation:
|
||||
std::unique_ptr<EndpointChannel> CreateUpgradedEndpointChannel(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id,
|
||||
const UpgradePathInfo& upgrade_path_info) final;
|
||||
Medium GetUpgradeMedium() const final { return Medium::WIFI_HOTSPOT; }
|
||||
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 {}
|
||||
|
||||
|
||||
@@ -12,19 +12,32 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "connections/implementation/wifi_hotspot_bwu_handler.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/feature_flags.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/single_thread_executor.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
namespace {
|
||||
using ::location::nearby::connections::OfflineFrame;
|
||||
using ::location::nearby::proto::connections::OperationResultCode;
|
||||
constexpr absl::Duration kWaitDuration = absl::Milliseconds(1000);
|
||||
} // namespace
|
||||
|
||||
@@ -91,17 +104,22 @@ TEST_F(WifiHotspotTest, SoftAPBWUInit_STACreateEndpointChannel) {
|
||||
auto bwu_frame =
|
||||
upgrade_frame.result().v1().bandwidth_upgrade_negotiation();
|
||||
|
||||
std::unique_ptr<EndpointChannel> new_channel =
|
||||
ErrorOr<std::unique_ptr<EndpointChannel>> result =
|
||||
handler_2->CreateUpgradedEndpointChannel(&client_2, /*service_id=*/"A",
|
||||
/*endpoint_id=*/"1",
|
||||
bwu_frame.upgrade_path_info());
|
||||
if (!FeatureFlags::GetInstance().GetFlags().enable_cancellation_flag) {
|
||||
ASSERT_TRUE(result.has_value());
|
||||
std::unique_ptr<EndpointChannel> new_channel = std::move(result.value());
|
||||
EXPECT_TRUE(accept_latch.Await(kWaitDuration).result());
|
||||
EXPECT_EQ(new_channel->GetMedium(),
|
||||
location::nearby::proto::connections::Medium::WIFI_HOTSPOT);
|
||||
} else {
|
||||
EXPECT_FALSE(result.has_value());
|
||||
EXPECT_TRUE(result.has_error());
|
||||
EXPECT_EQ(result.error().operation_result_code(),
|
||||
OperationResultCode::DETAIL_UNKNOWN);
|
||||
accept_latch.CountDown();
|
||||
EXPECT_EQ(new_channel, nullptr);
|
||||
}
|
||||
EXPECT_TRUE(mediums_2.GetWifiHotspot().IsConnectedToHotspot());
|
||||
handler_2->RevertResponderState(/*service_id=*/"A");
|
||||
|
||||
@@ -14,13 +14,20 @@
|
||||
|
||||
#include "connections/implementation/wifi_lan_bwu_handler.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/functional/bind_front.h"
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "connections/implementation/wifi_lan_endpoint_channel.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/implementation/wifi_utils.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/wifi_lan.h"
|
||||
@@ -28,6 +35,11 @@
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
namespace {
|
||||
using ::location::nearby::proto::connections::OperationResultCode;
|
||||
} // namespace
|
||||
|
||||
// TODO(edwinwu): Add exact OperationResultCode for WifiLanBwuHandler.
|
||||
WifiLanBwuHandler::WifiLanBwuHandler(
|
||||
Mediums& mediums, IncomingConnectionCallback incoming_connection_callback)
|
||||
: BaseBwuHandler(std::move(incoming_connection_callback)),
|
||||
@@ -35,19 +47,19 @@ WifiLanBwuHandler::WifiLanBwuHandler(
|
||||
|
||||
// Called by BWU target. Retrieves a new medium info from incoming message,
|
||||
// and establishes connection over WifiLan using this info.
|
||||
std::unique_ptr<EndpointChannel>
|
||||
ErrorOr<std::unique_ptr<EndpointChannel>>
|
||||
WifiLanBwuHandler::CreateUpgradedEndpointChannel(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id, const UpgradePathInfo& upgrade_path_info) {
|
||||
if (!upgrade_path_info.has_wifi_lan_socket()) {
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
const 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()) {
|
||||
NEARBY_LOGS(ERROR) << "WifiLanBwuHandler failed to parse UpgradePathInfo.";
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
const std::string& ip_address = upgrade_path_info_socket.ip_address();
|
||||
@@ -64,7 +76,7 @@ WifiLanBwuHandler::CreateUpgradedEndpointChannel(
|
||||
<< "WifiLanBwuHandler failed to connect to the WifiLan service ("
|
||||
<< WifiUtils::GetHumanReadableIpAddress(ip_address) << ":" << port
|
||||
<< ") for endpoint " << endpoint_id;
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
NEARBY_VLOG(1)
|
||||
@@ -80,10 +92,10 @@ WifiLanBwuHandler::CreateUpgradedEndpointChannel(
|
||||
<< "channel to the WifiLan service (" << ip_address
|
||||
<< ":" << port << ") for endpoint " << endpoint_id;
|
||||
socket.Close();
|
||||
return nullptr;
|
||||
return {Error(OperationResultCode::DETAIL_UNKNOWN)};
|
||||
}
|
||||
|
||||
return channel;
|
||||
return {std::move(channel)};
|
||||
}
|
||||
|
||||
// Called by BWU initiator. Set up WifiLan upgraded medium for this endpoint,
|
||||
@@ -143,12 +155,12 @@ void WifiLanBwuHandler::HandleRevertInitiatorStateForService(
|
||||
void WifiLanBwuHandler::OnIncomingWifiLanConnection(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
WifiLanSocket socket) {
|
||||
auto channel = absl::make_unique<WifiLanEndpointChannel>(
|
||||
auto channel = std::make_unique<WifiLanEndpointChannel>(
|
||||
upgrade_service_id, /*channel_name=*/upgrade_service_id, socket);
|
||||
std::unique_ptr<IncomingSocketConnection> connection(
|
||||
new IncomingSocketConnection{
|
||||
.socket = absl::make_unique<WifiLanIncomingSocket>(upgrade_service_id,
|
||||
socket),
|
||||
.socket = std::make_unique<WifiLanIncomingSocket>(upgrade_service_id,
|
||||
socket),
|
||||
.channel = std::move(channel),
|
||||
});
|
||||
NotifyOnIncomingConnection(client, std::move(connection));
|
||||
|
||||
@@ -15,12 +15,19 @@
|
||||
#ifndef CORE_INTERNAL_WIFI_LAN_BWU_HANDLER_H_
|
||||
#define CORE_INTERNAL_WIFI_LAN_BWU_HANDLER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "connections/implementation/base_bwu_handler.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel_manager.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/mediums/wifi_lan.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/wifi_lan.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -49,11 +56,14 @@ class WifiLanBwuHandler : public BaseBwuHandler {
|
||||
};
|
||||
|
||||
// BwuHandler implementation:
|
||||
std::unique_ptr<EndpointChannel> CreateUpgradedEndpointChannel(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id,
|
||||
const UpgradePathInfo& upgrade_path_info) final;
|
||||
Medium GetUpgradeMedium() const final { return Medium::WIFI_LAN; }
|
||||
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 {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user