mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Replace ByteArray with std::string.
PiperOrigin-RevId: 900893850
This commit is contained in:
committed by
Copybara-Service
parent
c90e273160
commit
dacbd03aa1
@@ -185,7 +185,7 @@ AwdlBwuHandler::CreateUpgradedEndpointChannel(
|
||||
// Called by BWU initiator. Set up AWDL upgraded medium for this endpoint,
|
||||
// and returns a upgrade path info (service_name, port) for remote party to
|
||||
// perform discovery.
|
||||
ByteArray AwdlBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string AwdlBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) {
|
||||
if (!awdl_medium_.IsAcceptingConnections(upgrade_service_id)) {
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "connections/implementation/mediums/awdl.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "internal/platform/awdl.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/nsd_service_info.h"
|
||||
|
||||
@@ -68,7 +67,7 @@ class AwdlBwuHandler : public BaseBwuHandler {
|
||||
const std::string& endpoint_id) final {}
|
||||
|
||||
// BaseBwuHandler implementation:
|
||||
ByteArray HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) final;
|
||||
void HandleRevertInitiatorStateForService(
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#include "internal/analytics/mock_event_logger.h"
|
||||
#include "internal/analytics/sharing_log_matchers.h"
|
||||
#include "internal/platform/awdl.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/exception.h"
|
||||
@@ -211,10 +210,10 @@ TEST_F(AwdlBwuHandlerTest,
|
||||
EXPECT_CALL(*awdl_medium_mock, ListenForService(_, 0))
|
||||
.WillOnce(Return(ByMove(nullptr)));
|
||||
|
||||
ByteArray result = handler_.InitializeUpgradedMediumForEndpoint(
|
||||
std::string result = handler_.InitializeUpgradedMediumForEndpoint(
|
||||
&client, std::string(kServiceId), std::string(kEndpointId));
|
||||
|
||||
EXPECT_TRUE(result.Empty());
|
||||
EXPECT_TRUE(result.empty());
|
||||
MediumEnvironment::Instance().Stop();
|
||||
}
|
||||
|
||||
@@ -262,10 +261,10 @@ TEST_F(AwdlBwuHandlerTest, InitializeUpgradedMediumForEndpoint_Success) {
|
||||
return true;
|
||||
});
|
||||
|
||||
ByteArray result = handler_.InitializeUpgradedMediumForEndpoint(
|
||||
std::string result = handler_.InitializeUpgradedMediumForEndpoint(
|
||||
&client, std::string(kServiceId), std::string(kEndpointId));
|
||||
|
||||
EXPECT_FALSE(result.Empty());
|
||||
EXPECT_FALSE(result.empty());
|
||||
OfflineFrame expected_frame;
|
||||
expected_frame.set_version(OfflineFrame::V1);
|
||||
expected_frame.mutable_v1()->set_type(
|
||||
@@ -290,7 +289,7 @@ TEST_F(AwdlBwuHandlerTest, InitializeUpgradedMediumForEndpoint_Success) {
|
||||
// parser::ForBwuAwdlPathAvailable which puts the generated password. We
|
||||
// will extract it from result directly to build expected frame.
|
||||
OfflineFrame result_frame;
|
||||
EXPECT_TRUE(result_frame.ParseFromString(std::string(result)));
|
||||
EXPECT_TRUE(result_frame.ParseFromString(result));
|
||||
awdl_credentials->set_password(result_frame.v1()
|
||||
.bandwidth_upgrade_negotiation()
|
||||
.upgrade_path_info()
|
||||
@@ -398,9 +397,9 @@ TEST_F(AwdlBwuHandlerTest, OnIncomingAwdlConnection_Success) {
|
||||
std::unique_ptr<BwuHandler::IncomingSocketConnection>
|
||||
connection) { latch.CountDown(); });
|
||||
|
||||
ByteArray result = handler_.InitializeUpgradedMediumForEndpoint(
|
||||
std::string result = handler_.InitializeUpgradedMediumForEndpoint(
|
||||
&client, std::string(kServiceId), std::string(kEndpointId));
|
||||
EXPECT_FALSE(result.Empty());
|
||||
EXPECT_FALSE(result.empty());
|
||||
|
||||
auto await_result = latch.Await(absl::Seconds(5));
|
||||
EXPECT_TRUE(await_result.ok());
|
||||
@@ -448,9 +447,9 @@ TEST_F(AwdlBwuHandlerTest, AwdlIncomingSocket_ToStringAndClose) {
|
||||
latch.CountDown();
|
||||
});
|
||||
|
||||
ByteArray result = handler_.InitializeUpgradedMediumForEndpoint(
|
||||
std::string result = handler_.InitializeUpgradedMediumForEndpoint(
|
||||
&client, std::string(kServiceId), std::string(kEndpointId));
|
||||
EXPECT_FALSE(result.Empty());
|
||||
EXPECT_FALSE(result.empty());
|
||||
|
||||
auto await_result = latch.Await(absl::Seconds(5));
|
||||
EXPECT_TRUE(await_result.ok());
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#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 {
|
||||
@@ -30,16 +29,16 @@ BaseBwuHandler::BaseBwuHandler(
|
||||
IncomingConnectionCallback incoming_connection_callback)
|
||||
: incoming_connection_callback_(std::move(incoming_connection_callback)) {}
|
||||
|
||||
ByteArray BaseBwuHandler::InitializeUpgradedMediumForEndpoint(
|
||||
std::string BaseBwuHandler::InitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id) {
|
||||
std::string upgrade_service_id = WrapInitiatorUpgradeServiceId(service_id);
|
||||
|
||||
// Perform any medium-specific handling in the child class.
|
||||
ByteArray upgrade_path_available_frame =
|
||||
std::string upgrade_path_available_frame =
|
||||
HandleInitializeUpgradedMediumForEndpoint(client, upgrade_service_id,
|
||||
endpoint_id);
|
||||
if (!upgrade_path_available_frame.Empty()) {
|
||||
if (!upgrade_path_available_frame.empty()) {
|
||||
upgrade_service_id_to_active_endpoint_ids_[upgrade_service_id].insert(
|
||||
endpoint_id);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "connections/implementation/bwu_handler.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -35,7 +34,7 @@ class BaseBwuHandler : public BwuHandler {
|
||||
IncomingConnectionCallback incoming_connection_callback);
|
||||
|
||||
// BwuHandler implementation:
|
||||
ByteArray InitializeUpgradedMediumForEndpoint(
|
||||
std::string InitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id) final;
|
||||
void RevertInitiatorState() final;
|
||||
@@ -51,7 +50,7 @@ class BaseBwuHandler : public BwuHandler {
|
||||
// respectively, to handle medium-specific logic.
|
||||
// HandleRevertInitiatorStateForService is only invoked after the last
|
||||
// endpoint for the service is reverted.
|
||||
virtual ByteArray HandleInitializeUpgradedMediumForEndpoint(
|
||||
virtual std::string HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) = 0;
|
||||
virtual void HandleRevertInitiatorStateForService(
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#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 {
|
||||
@@ -55,8 +54,8 @@ class BwuHandlerImpl : public BaseBwuHandler {
|
||||
const std::vector<InputData>& handle_revert_calls() const {
|
||||
return handle_revert_calls_;
|
||||
}
|
||||
void set_handle_initialize_output(ByteArray bytes) {
|
||||
handle_initialize_output_ = bytes;
|
||||
void set_handle_initialize_output(absl::string_view bytes) {
|
||||
handle_initialize_output_ = std::string(bytes);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -73,7 +72,7 @@ class BwuHandlerImpl : public BaseBwuHandler {
|
||||
const std::string& endpoint_id) final {}
|
||||
|
||||
// BaseBwuHandler implementation:
|
||||
ByteArray HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) final {
|
||||
handle_initialize_calls_.push_back({.client = client,
|
||||
@@ -86,7 +85,7 @@ class BwuHandlerImpl : public BaseBwuHandler {
|
||||
handle_revert_calls_.push_back({.service_id = upgrade_service_id});
|
||||
}
|
||||
|
||||
ByteArray handle_initialize_output_;
|
||||
std::string handle_initialize_output_;
|
||||
std::vector<InputData> handle_initialize_calls_;
|
||||
std::vector<InputData> handle_revert_calls_;
|
||||
};
|
||||
@@ -95,7 +94,7 @@ TEST(BaseBwuHandlerTest, InitializeAndRevert) {
|
||||
ClientProxy client;
|
||||
BwuHandlerImpl handler;
|
||||
|
||||
ByteArray expected_output{"not empty"};
|
||||
absl::string_view expected_output{"not empty"};
|
||||
handler.set_handle_initialize_output(expected_output);
|
||||
|
||||
// Initialize two upgrade endpoints for service A and one for service B.
|
||||
@@ -150,7 +149,7 @@ TEST(BaseBwuHandlerTest, InitializeAndRevertAll) {
|
||||
ClientProxy client;
|
||||
BwuHandlerImpl handler;
|
||||
|
||||
ByteArray expected_output{"not empty"};
|
||||
absl::string_view expected_output{"not empty"};
|
||||
handler.set_handle_initialize_output(expected_output);
|
||||
|
||||
handler.InitializeUpgradedMediumForEndpoint(&client, /*service_id=*/"A",
|
||||
@@ -169,7 +168,7 @@ TEST(BaseBwuHandlerTest, Initialize_Failure_EmptyUpgradePathAvailableFrame) {
|
||||
ClientProxy client;
|
||||
BwuHandlerImpl handler;
|
||||
|
||||
ByteArray expected_output{};
|
||||
absl::string_view expected_output{};
|
||||
handler.set_handle_initialize_output(expected_output);
|
||||
|
||||
handler.InitializeUpgradedMediumForEndpoint(&client, /*service_id=*/"A",
|
||||
@@ -191,7 +190,7 @@ TEST(BaseBwuHandlerTest, Initialize_StillWorkWithUpgradeServiceIdSuffix) {
|
||||
ClientProxy client;
|
||||
BwuHandlerImpl handler;
|
||||
|
||||
ByteArray expected_output{"not empty"};
|
||||
absl::string_view expected_output{"not empty"};
|
||||
handler.set_handle_initialize_output(expected_output);
|
||||
|
||||
// The method should be robust and not add _another_ upgrade suffix
|
||||
@@ -208,7 +207,7 @@ TEST(BaseBwuHandlerTest, Revert_Failure_CantFindService) {
|
||||
ClientProxy client;
|
||||
BwuHandlerImpl handler;
|
||||
|
||||
ByteArray expected_output{"not empty"};
|
||||
absl::string_view expected_output{"not empty"};
|
||||
handler.set_handle_initialize_output(expected_output);
|
||||
handler.InitializeUpgradedMediumForEndpoint(&client, /*service_id=*/"A",
|
||||
/*endpoint_id=*/"1");
|
||||
@@ -222,7 +221,7 @@ TEST(BaseBwuHandlerTest, Revert_Failure_CantFindEndpoint) {
|
||||
ClientProxy client;
|
||||
BwuHandlerImpl handler;
|
||||
|
||||
ByteArray expected_output{"not empty"};
|
||||
absl::string_view expected_output{"not empty"};
|
||||
handler.set_handle_initialize_output(expected_output);
|
||||
handler.InitializeUpgradedMediumForEndpoint(&client, /*service_id=*/"A",
|
||||
/*endpoint_id=*/"1");
|
||||
|
||||
@@ -157,7 +157,7 @@ ExceptionOr<ByteArray> BaseEndpointChannel::Read(
|
||||
// and let it through if it is, otherwise message is erased.
|
||||
// TODO(apolyudov): verify this happens at most once per session.
|
||||
result = {};
|
||||
auto parsed = parser::FromBytes(ByteArray(input));
|
||||
auto parsed = parser::FromBytes(input);
|
||||
if (parsed.ok()) {
|
||||
if (parser::GetFrameType(parsed.result()) ==
|
||||
location::nearby::connections::V1Frame::KEEP_ALIVE) {
|
||||
@@ -190,9 +190,9 @@ ExceptionOr<ByteArray> BaseEndpointChannel::Read(
|
||||
return ExceptionOr<ByteArray>(result);
|
||||
}
|
||||
|
||||
Exception BaseEndpointChannel::Write(const ByteArray& data) {
|
||||
Exception BaseEndpointChannel::Write(absl::string_view data) {
|
||||
PacketMetaData packet_meta_data;
|
||||
return Write(data.AsStringView(), packet_meta_data);
|
||||
return Write(data, packet_meta_data);
|
||||
}
|
||||
|
||||
Exception BaseEndpointChannel::Write(absl::string_view data,
|
||||
|
||||
@@ -55,7 +55,7 @@ class BaseEndpointChannel : public EndpointChannel {
|
||||
ExceptionOr<ByteArray> Read(PacketMetaData& packet_meta_data)
|
||||
ABSL_LOCKS_EXCLUDED(reader_mutex_, crypto_mutex_,
|
||||
last_read_mutex_) override;
|
||||
Exception Write(const ByteArray& data) override;
|
||||
Exception Write(absl::string_view data) override;
|
||||
Exception Write(absl::string_view data, PacketMetaData& packet_meta_data)
|
||||
ABSL_LOCKS_EXCLUDED(writer_mutex_, crypto_mutex_) override;
|
||||
void Close() ABSL_LOCKS_EXCLUDED(is_paused_mutex_) override;
|
||||
|
||||
@@ -174,7 +174,7 @@ class BaseEndpointChannelTest : public ::testing::Test {
|
||||
NearbyFlags::GetInstance().ResetOverridedValues();
|
||||
}
|
||||
|
||||
const ByteArray kTestData{"test_data"};
|
||||
const absl::string_view kTestData = "test_data";
|
||||
};
|
||||
|
||||
TEST_F(BaseEndpointChannelTest, ReadSucceedsWhenFlagDisabled) {
|
||||
@@ -189,7 +189,7 @@ TEST_F(BaseEndpointChannelTest, ReadSucceedsWhenFlagDisabled) {
|
||||
|
||||
channel_a.Write(kTestData);
|
||||
ByteArray rx_message = std::move(channel_b.Read().result());
|
||||
EXPECT_EQ(rx_message, kTestData);
|
||||
EXPECT_EQ(rx_message.AsStringView(), kTestData);
|
||||
}
|
||||
|
||||
TEST_F(BaseEndpointChannelTest, ReadCallsDispatchPacketWhenFlagEnabled) {
|
||||
@@ -203,13 +203,14 @@ TEST_F(BaseEndpointChannelTest, ReadCallsDispatchPacketWhenFlagEnabled) {
|
||||
TestEndpointChannel channel_b(pipe_a.first.get(), pipe_b.second.get());
|
||||
|
||||
EXPECT_CALL(channel_b, DispatchPacket)
|
||||
.WillOnce(::testing::Return(ExceptionOr<ByteArray>(kTestData)));
|
||||
.WillOnce(::testing::Return(
|
||||
ExceptionOr<ByteArray>(ByteArray(std::string(kTestData)))));
|
||||
|
||||
channel_a.Write(kTestData);
|
||||
|
||||
auto read_byte = channel_b.Read();
|
||||
EXPECT_TRUE(read_byte.ok());
|
||||
EXPECT_EQ(read_byte.result(), kTestData);
|
||||
EXPECT_EQ(read_byte.result().AsStringView(), kTestData);
|
||||
}
|
||||
|
||||
TEST_F(BaseEndpointChannelTest,
|
||||
@@ -243,10 +244,10 @@ TEST_F(BaseEndpointChannelTest, ReadWrite) {
|
||||
auto pipe_b = CreatePipe(); // channel_b writes to pipe_b, reads from pipe_a.
|
||||
TestEndpointChannel channel_a(pipe_b.first.get(), pipe_a.second.get());
|
||||
TestEndpointChannel channel_b(pipe_a.first.get(), pipe_b.second.get());
|
||||
ByteArray tx_message{"data message"};
|
||||
absl::string_view tx_message = "data message";
|
||||
channel_a.Write(tx_message);
|
||||
ByteArray rx_message = std::move(channel_b.Read().result());
|
||||
EXPECT_EQ(rx_message, tx_message);
|
||||
EXPECT_EQ(rx_message.AsStringView(), tx_message);
|
||||
}
|
||||
|
||||
TEST_F(BaseEndpointChannelTest, ChannelUnencryptedByDefault) {
|
||||
@@ -332,12 +333,12 @@ TEST_F(BaseEndpointChannelTest, NotEncryptedReadWriteCanBeIntercepted) {
|
||||
EXPECT_EQ(channel_b.GetType(), "BLE");
|
||||
|
||||
// Start data transfer
|
||||
ByteArray tx_message{"data message"};
|
||||
absl::string_view tx_message = "data message";
|
||||
channel_a.Write(tx_message);
|
||||
ByteArray rx_message = std::move(channel_b.Read().result());
|
||||
|
||||
// Verify expectations.
|
||||
EXPECT_EQ(rx_message, tx_message);
|
||||
EXPECT_EQ(rx_message.AsStringView(), tx_message);
|
||||
{
|
||||
absl::MutexLock lock(mutex);
|
||||
std::string message{tx_message};
|
||||
@@ -396,12 +397,12 @@ TEST_F(BaseEndpointChannelTest, EncryptedReadWriteCanNotBeIntercepted) {
|
||||
EXPECT_TRUE(channel_b.IsEncrypted());
|
||||
|
||||
// Start data transfer
|
||||
ByteArray tx_message{"data message"};
|
||||
absl::string_view tx_message = "data message";
|
||||
channel_a.Write(tx_message);
|
||||
ByteArray rx_message = std::move(channel_b.Read().result());
|
||||
|
||||
// Verify expectations.
|
||||
EXPECT_EQ(rx_message, tx_message);
|
||||
EXPECT_EQ(rx_message.AsStringView(), tx_message);
|
||||
{
|
||||
absl::MutexLock lock(mutex);
|
||||
std::string message{tx_message};
|
||||
@@ -432,8 +433,8 @@ TEST_F(BaseEndpointChannelTest, CanBesuspendedAndResumed) {
|
||||
EXPECT_EQ(channel_b.GetType(), "WIFI_LAN");
|
||||
|
||||
// Start data transfer
|
||||
ByteArray tx_message{"data message"};
|
||||
ByteArray more_message{"more data"};
|
||||
absl::string_view tx_message = "data message";
|
||||
absl::string_view more_message = "more data";
|
||||
channel_a.Write(tx_message);
|
||||
ByteArray rx_message = std::move(channel_b.Read().result());
|
||||
|
||||
@@ -459,7 +460,7 @@ TEST_F(BaseEndpointChannelTest, CanBesuspendedAndResumed) {
|
||||
// Resume; verify that data transfer comepleted.
|
||||
channel_a.Resume();
|
||||
EXPECT_TRUE(latch.Await(absl::Milliseconds(1000)).result());
|
||||
EXPECT_EQ(read_more, more_message);
|
||||
EXPECT_EQ(read_more.AsStringView(), more_message);
|
||||
|
||||
// Shutdown test environment.
|
||||
channel_a.Close(DisconnectionReason::LOCAL_DISCONNECTION);
|
||||
@@ -506,14 +507,14 @@ TEST_F(BaseEndpointChannelTest, ReadUnencryptedFrameOnEncryptedChannel) {
|
||||
EXPECT_EQ(channel_b.GetType(), "ENCRYPTED_BLUETOOTH");
|
||||
|
||||
// An unencrypted KeepAlive should succeed.
|
||||
ByteArray keep_alive_message = parser::ForKeepAlive();
|
||||
std::string keep_alive_message = parser::ForKeepAlive();
|
||||
channel_a.Write(keep_alive_message);
|
||||
ExceptionOr<ByteArray> result = channel_b.Read();
|
||||
EXPECT_TRUE(result.ok());
|
||||
EXPECT_EQ(result.result(), keep_alive_message);
|
||||
EXPECT_EQ(result.result().AsStringView(), keep_alive_message);
|
||||
|
||||
// An unencrypted data frame should fail.
|
||||
ByteArray tx_message{"data message"};
|
||||
absl::string_view tx_message = "data message";
|
||||
channel_a.Write(tx_message);
|
||||
result = channel_b.Read();
|
||||
EXPECT_FALSE(result.ok());
|
||||
|
||||
@@ -2477,8 +2477,8 @@ ExceptionOr<OfflineFrame> BasePcpHandler::ReadConnectionRequestFrame(
|
||||
return ExceptionOr<OfflineFrame>(wrapped_bytes.exception());
|
||||
}
|
||||
|
||||
ByteArray bytes = std::move(wrapped_bytes.result());
|
||||
ExceptionOr<OfflineFrame> wrapped_frame = parser::FromBytes(bytes);
|
||||
ExceptionOr<OfflineFrame> wrapped_frame =
|
||||
parser::FromBytes(wrapped_bytes.result().AsStringView());
|
||||
if (wrapped_frame.GetException().Raised(Exception::kInvalidProtocolBuffer)) {
|
||||
return ExceptionOr<OfflineFrame>(Exception::kIo);
|
||||
}
|
||||
|
||||
@@ -88,7 +88,6 @@ using ::nearby::analytics::HasEventType;
|
||||
using ::testing::_;
|
||||
using ::testing::AtLeast;
|
||||
using ::protobuf_matchers::EqualsProto;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::Matcher;
|
||||
using ::testing::MockFunction;
|
||||
using ::testing::NiceMock;
|
||||
@@ -171,7 +170,7 @@ class MockEndpointChannel : public BaseEndpointChannel {
|
||||
output_stream_(std::move(writer)) {}
|
||||
|
||||
ExceptionOr<ByteArray> DoRead() { return BaseEndpointChannel::Read(); }
|
||||
Exception DoWrite(const ByteArray& data) {
|
||||
Exception DoWrite(absl::string_view data) {
|
||||
if (broken_write_) {
|
||||
return {Exception::kFailed};
|
||||
}
|
||||
@@ -182,7 +181,7 @@ class MockEndpointChannel : public BaseEndpointChannel {
|
||||
}
|
||||
|
||||
MOCK_METHOD(ExceptionOr<ByteArray>, Read, (), (override));
|
||||
MOCK_METHOD(Exception, Write, (const ByteArray& data), (override));
|
||||
MOCK_METHOD(Exception, Write, (absl::string_view data), (override));
|
||||
MOCK_METHOD(void, CloseImpl, (), (override));
|
||||
MOCK_METHOD(location::nearby::proto::connections::Medium, GetMedium, (),
|
||||
(const, override));
|
||||
@@ -576,26 +575,26 @@ class BasePcpHandlerTest
|
||||
// the peer channel. The rest of the exchange must happen for the benefit of
|
||||
// DH key exchange.
|
||||
EXPECT_CALL(*channel_a, Read())
|
||||
.WillRepeatedly(Invoke(
|
||||
[channel = channel_a.get()]() { return channel->DoRead(); }));
|
||||
.WillRepeatedly(
|
||||
[channel = channel_a.get()]() { return channel->DoRead(); });
|
||||
EXPECT_CALL(*channel_a, Write(_))
|
||||
.WillOnce(Return(Exception{Exception::kSuccess}))
|
||||
.WillRepeatedly(
|
||||
Invoke([channel = channel_a.get()](const ByteArray& data) {
|
||||
[channel = channel_a.get()](absl::string_view data) {
|
||||
return channel->DoWrite(data);
|
||||
}));
|
||||
});
|
||||
EXPECT_CALL(*channel_a, GetMedium).WillRepeatedly(Return(medium));
|
||||
EXPECT_CALL(*channel_a, GetLastReadTimestamp)
|
||||
.WillRepeatedly(Return(absl::Now()));
|
||||
EXPECT_CALL(*channel_a, IsPaused).WillRepeatedly(Return(false));
|
||||
EXPECT_CALL(*channel_b, Read())
|
||||
.WillRepeatedly(Invoke(
|
||||
[channel = channel_b.get()]() { return channel->DoRead(); }));
|
||||
.WillRepeatedly(
|
||||
[channel = channel_b.get()]() { return channel->DoRead(); });
|
||||
EXPECT_CALL(*channel_b, Write(_))
|
||||
.WillRepeatedly(
|
||||
Invoke([channel = channel_b.get()](const ByteArray& data) {
|
||||
[channel = channel_b.get()](absl::string_view data) {
|
||||
return channel->DoWrite(data);
|
||||
}));
|
||||
});
|
||||
EXPECT_CALL(*channel_b, GetMedium).WillRepeatedly(Return(medium));
|
||||
EXPECT_CALL(*channel_b, GetLastReadTimestamp)
|
||||
.WillRepeatedly(Return(absl::Now()));
|
||||
@@ -622,20 +621,20 @@ class BasePcpHandlerTest
|
||||
// the peer channel. The rest of the exchange must happen for the benefit of
|
||||
// DH key exchange.
|
||||
EXPECT_CALL(*channel_a, Read())
|
||||
.WillRepeatedly(Invoke(
|
||||
[channel = channel_a.get()]() { return channel->DoRead(); }));
|
||||
.WillRepeatedly(
|
||||
[channel = channel_a.get()]() { return channel->DoRead(); });
|
||||
EXPECT_CALL(*channel_a, GetMedium).WillRepeatedly(Return(medium));
|
||||
EXPECT_CALL(*channel_a, GetLastReadTimestamp)
|
||||
.WillRepeatedly(Return(absl::Now()));
|
||||
EXPECT_CALL(*channel_a, IsPaused).WillRepeatedly(Return(false));
|
||||
EXPECT_CALL(*channel_b, Read())
|
||||
.WillRepeatedly(Invoke(
|
||||
[channel = channel_b.get()]() { return channel->DoRead(); }));
|
||||
.WillRepeatedly(
|
||||
[channel = channel_b.get()]() { return channel->DoRead(); });
|
||||
EXPECT_CALL(*channel_b, Write(_))
|
||||
.WillRepeatedly(
|
||||
Invoke([channel = channel_b.get()](const ByteArray& data) {
|
||||
[channel = channel_b.get()](absl::string_view data) {
|
||||
return channel->DoWrite(data);
|
||||
}));
|
||||
});
|
||||
EXPECT_CALL(*channel_b, GetMedium).WillRepeatedly(Return(medium));
|
||||
EXPECT_CALL(*channel_b, GetLastReadTimestamp)
|
||||
.WillRepeatedly(Return(absl::Now()));
|
||||
@@ -675,15 +674,15 @@ class BasePcpHandlerTest
|
||||
auto allowed_mediums = pcp_handler->GetDiscoveryMediums(client);
|
||||
|
||||
EXPECT_CALL(*pcp_handler, ConnectImpl)
|
||||
.WillOnce(Invoke([&channel_a, connect_medium](
|
||||
ClientProxy* client,
|
||||
MockPcpHandler::DiscoveredEndpoint* endpoint) {
|
||||
.WillOnce([&channel_a, connect_medium](
|
||||
ClientProxy* client,
|
||||
MockPcpHandler::DiscoveredEndpoint* endpoint) {
|
||||
return MockPcpHandler::ConnectImplResult{
|
||||
.medium = connect_medium,
|
||||
.status = {Status::kSuccess},
|
||||
.endpoint_channel = std::move(channel_a),
|
||||
};
|
||||
}));
|
||||
});
|
||||
|
||||
for (const auto& discovered_medium : allowed_mediums) {
|
||||
pcp_handler->OnEndpointFound(
|
||||
@@ -756,15 +755,15 @@ class BasePcpHandlerTest
|
||||
|
||||
EXPECT_CALL(*pcp_handler, ConnectImpl)
|
||||
.WillRepeatedly(
|
||||
Invoke([&channel_a, connect_medium](
|
||||
ClientProxy* client,
|
||||
MockPcpHandler::DiscoveredEndpoint* endpoint) {
|
||||
[&channel_a, connect_medium](
|
||||
ClientProxy* client,
|
||||
MockPcpHandler::DiscoveredEndpoint* endpoint) {
|
||||
return MockPcpHandler::ConnectImplResult{
|
||||
.medium = connect_medium,
|
||||
.status = {Status::kSuccess},
|
||||
.endpoint_channel = std::move(channel_a),
|
||||
};
|
||||
}));
|
||||
});
|
||||
|
||||
for (const auto& discovered_medium : allowed_mediums) {
|
||||
pcp_handler->OnEndpointFound(
|
||||
@@ -824,8 +823,8 @@ class BasePcpHandlerTest
|
||||
|
||||
EXPECT_CALL(*pcp_handler, ConnectImpl)
|
||||
.WillRepeatedly(
|
||||
Invoke([&channel_a](ClientProxy* client,
|
||||
MockPcpHandler::DiscoveredEndpoint* endpoint) {
|
||||
[&channel_a](ClientProxy* client,
|
||||
MockPcpHandler::DiscoveredEndpoint* endpoint) {
|
||||
if (endpoint->medium ==
|
||||
location::nearby::proto::connections::WIFI_LAN) {
|
||||
LOG(INFO) << "Connect with Medium WIFI_LAN failed.";
|
||||
@@ -844,7 +843,7 @@ class BasePcpHandlerTest
|
||||
.endpoint_channel = std::move(channel_a),
|
||||
};
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
for (const auto& discovered_medium : allowed_mediums) {
|
||||
pcp_handler->OnEndpointFound(
|
||||
@@ -1353,7 +1352,7 @@ TEST_P(BasePcpHandlerTest, RequestConnectionV3_ConnectImplFailure) {
|
||||
auto allowed_mediums = pcp_handler.GetDiscoveryMediums(client_.get());
|
||||
|
||||
EXPECT_CALL(pcp_handler, ConnectImpl)
|
||||
.WillRepeatedly(Invoke(
|
||||
.WillRepeatedly(
|
||||
[connect_medium](ClientProxy* client,
|
||||
MockPcpHandler::DiscoveredEndpoint* endpoint) {
|
||||
return MockPcpHandler::ConnectImplResult{
|
||||
@@ -1361,7 +1360,7 @@ TEST_P(BasePcpHandlerTest, RequestConnectionV3_ConnectImplFailure) {
|
||||
.status = {Status::kError},
|
||||
.endpoint_channel = nullptr,
|
||||
};
|
||||
}));
|
||||
});
|
||||
|
||||
for (const auto& discovered_medium : allowed_mediums) {
|
||||
pcp_handler.OnEndpointFound(
|
||||
@@ -1428,7 +1427,7 @@ TEST_P(BasePcpHandlerTest, RequestConnection_ConnectImplFailure) {
|
||||
auto allowed_mediums = pcp_handler.GetDiscoveryMediums(client_.get());
|
||||
|
||||
EXPECT_CALL(pcp_handler, ConnectImpl)
|
||||
.WillRepeatedly(Invoke(
|
||||
.WillRepeatedly(
|
||||
[connect_medium](ClientProxy* client,
|
||||
MockPcpHandler::DiscoveredEndpoint* endpoint) {
|
||||
return MockPcpHandler::ConnectImplResult{
|
||||
@@ -1436,7 +1435,7 @@ TEST_P(BasePcpHandlerTest, RequestConnection_ConnectImplFailure) {
|
||||
.status = {Status::kError},
|
||||
.endpoint_channel = nullptr,
|
||||
};
|
||||
}));
|
||||
});
|
||||
|
||||
for (const auto& discovered_medium : allowed_mediums) {
|
||||
pcp_handler.OnEndpointFound(
|
||||
@@ -1787,7 +1786,7 @@ TEST_F(BasePcpHandlerTest, InjectEndpoint) {
|
||||
EXPECT_TRUE(client_->IsDiscovering());
|
||||
|
||||
EXPECT_CALL(pcp_handler, InjectEndpointImpl(client_.get(), service_id, _))
|
||||
.WillOnce(Invoke([&pcp_handler, &endpoint_id](
|
||||
.WillOnce([&pcp_handler, &endpoint_id](
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const OutOfBandConnectionMetadata& metadata) {
|
||||
pcp_handler.OnEndpointFound(
|
||||
@@ -1803,7 +1802,7 @@ TEST_F(BasePcpHandlerTest, InjectEndpoint) {
|
||||
MockContext{nullptr},
|
||||
}));
|
||||
return Status{Status::kSuccess};
|
||||
}));
|
||||
});
|
||||
pcp_handler.InjectEndpoint(
|
||||
client_.get(), service_id,
|
||||
OutOfBandConnectionMetadata{
|
||||
@@ -1851,30 +1850,30 @@ TEST_F(BasePcpHandlerTest,
|
||||
|
||||
::testing::InSequence seq;
|
||||
EXPECT_CALL(mock_discovery_listener_.endpoint_found_cb, Call)
|
||||
.WillOnce(Invoke([id = endpoint_id](const std::string& endpoint_id,
|
||||
.WillOnce([id = endpoint_id](const std::string& endpoint_id,
|
||||
const ByteArray& endpoint_info,
|
||||
const std::string& service_id) {
|
||||
EXPECT_EQ(endpoint_id, id);
|
||||
EXPECT_EQ(endpoint_info, ByteArray{"ABCD"});
|
||||
}));
|
||||
});
|
||||
|
||||
EXPECT_CALL(mock_discovery_listener_.endpoint_lost_cb, Call)
|
||||
.WillOnce(Invoke([id = endpoint_id](const std::string& endpoint_id) {
|
||||
.WillOnce([id = endpoint_id](const std::string& endpoint_id) {
|
||||
EXPECT_EQ(endpoint_id, id);
|
||||
}));
|
||||
});
|
||||
|
||||
EXPECT_CALL(mock_discovery_listener_.endpoint_found_cb, Call)
|
||||
.WillOnce(Invoke([id = endpoint_id](const std::string& endpoint_id,
|
||||
.WillOnce([id = endpoint_id](const std::string& endpoint_id,
|
||||
const ByteArray& endpoint_info,
|
||||
const std::string& service_id) {
|
||||
EXPECT_EQ(endpoint_id, id);
|
||||
EXPECT_EQ(endpoint_info, ByteArray{"ABCDEF"});
|
||||
}));
|
||||
});
|
||||
|
||||
EXPECT_CALL(mock_discovery_listener_.endpoint_lost_cb, Call)
|
||||
.WillOnce(Invoke([id = endpoint_id](const std::string& endpoint_id) {
|
||||
.WillOnce([id = endpoint_id](const std::string& endpoint_id) {
|
||||
EXPECT_EQ(endpoint_id, id);
|
||||
}));
|
||||
});
|
||||
|
||||
// Found endpoint on Bluetooth
|
||||
pcp_handler.OnEndpointFound(
|
||||
@@ -1964,7 +1963,7 @@ TEST_F(BasePcpHandlerTest, TestStartStopEndpointLostAlarm) {
|
||||
EXPECT_TRUE(client_->IsDiscovering());
|
||||
|
||||
EXPECT_CALL(pcp_handler, InjectEndpointImpl)
|
||||
.WillOnce(Invoke([&pcp_handler, &endpoint_id](
|
||||
.WillOnce([&pcp_handler, &endpoint_id](
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const OutOfBandConnectionMetadata& metadata) {
|
||||
pcp_handler.OnEndpointFound(
|
||||
@@ -1980,7 +1979,7 @@ TEST_F(BasePcpHandlerTest, TestStartStopEndpointLostAlarm) {
|
||||
MockContext{nullptr},
|
||||
}));
|
||||
return Status{Status::kSuccess};
|
||||
}));
|
||||
});
|
||||
pcp_handler.InjectEndpoint(
|
||||
client_.get(), service_id,
|
||||
OutOfBandConnectionMetadata{
|
||||
@@ -2027,7 +2026,7 @@ TEST_F(BasePcpHandlerTest, TestStartEndpointLostByMediumAlarms) {
|
||||
EXPECT_TRUE(client_->IsDiscovering());
|
||||
|
||||
EXPECT_CALL(pcp_handler, InjectEndpointImpl)
|
||||
.WillOnce(Invoke([&pcp_handler, &endpoint_id](
|
||||
.WillOnce([&pcp_handler, &endpoint_id](
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const OutOfBandConnectionMetadata& metadata) {
|
||||
pcp_handler.OnEndpointFound(
|
||||
@@ -2043,7 +2042,7 @@ TEST_F(BasePcpHandlerTest, TestStartEndpointLostByMediumAlarms) {
|
||||
MockContext{nullptr},
|
||||
}));
|
||||
return Status{Status::kSuccess};
|
||||
}));
|
||||
});
|
||||
pcp_handler.InjectEndpoint(
|
||||
client_.get(), service_id,
|
||||
OutOfBandConnectionMetadata{
|
||||
@@ -2094,7 +2093,7 @@ TEST_F(BasePcpHandlerTest, TestEndpointFoundStopsAlarm) {
|
||||
EXPECT_CALL(pcp_handler, InjectEndpointImpl)
|
||||
.Times(2)
|
||||
.WillRepeatedly(
|
||||
Invoke([&pcp_handler, &endpoint_id, &first_call](
|
||||
[&pcp_handler, &endpoint_id, &first_call](
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const OutOfBandConnectionMetadata& metadata) {
|
||||
ByteArray endpoint_info;
|
||||
@@ -2117,7 +2116,7 @@ TEST_F(BasePcpHandlerTest, TestEndpointFoundStopsAlarm) {
|
||||
MockContext{nullptr},
|
||||
}));
|
||||
return Status{Status::kSuccess};
|
||||
}));
|
||||
});
|
||||
pcp_handler.InjectEndpoint(
|
||||
client_.get(), service_id,
|
||||
OutOfBandConnectionMetadata{
|
||||
@@ -2271,20 +2270,20 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithUnknown) {
|
||||
ASSERT_TRUE(client_->IsListeningForIncomingConnections());
|
||||
ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get()));
|
||||
auto channel_pair = SetupConnection(Medium::BLUETOOTH);
|
||||
ByteArray serialized_frame = parser::ForConnectionRequestConnections(
|
||||
std::string serialized_frame = parser::ForConnectionRequestConnections(
|
||||
{}, {
|
||||
.local_endpoint_id = "ABCD",
|
||||
.local_endpoint_info = ByteArray("local endpoint"),
|
||||
});
|
||||
location::nearby::connections::OfflineFrame frame;
|
||||
frame.ParseFromString(serialized_frame.AsStringView());
|
||||
frame.ParseFromString(serialized_frame);
|
||||
frame.mutable_v1()->mutable_connection_request()->clear_connections_device();
|
||||
frame.mutable_v1()->mutable_connection_request()->clear_presence_device();
|
||||
ASSERT_FALSE(frame.v1().connection_request().has_connections_device());
|
||||
ASSERT_FALSE(frame.v1().connection_request().has_presence_device());
|
||||
// do a dummy write to get to the actual write.
|
||||
channel_pair.first->Write(ByteArray());
|
||||
channel_pair.first->Write(ByteArray(frame.SerializeAsString()));
|
||||
channel_pair.first->Write("");
|
||||
channel_pair.first->Write(frame.SerializeAsString());
|
||||
EXPECT_TRUE(pcp_handler
|
||||
.OnIncomingConnection(
|
||||
client_.get(), ByteArray("remote endpoint"),
|
||||
@@ -2321,20 +2320,20 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithUnknown) {
|
||||
ASSERT_TRUE(client_->IsListeningForIncomingConnections());
|
||||
ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get()));
|
||||
auto channel_pair = SetupConnection(Medium::BLUETOOTH);
|
||||
ByteArray serialized_frame = parser::ForConnectionRequestConnections(
|
||||
std::string serialized_frame = parser::ForConnectionRequestConnections(
|
||||
{}, {
|
||||
.local_endpoint_id = "ABCD",
|
||||
.local_endpoint_info = ByteArray("local endpoint"),
|
||||
});
|
||||
location::nearby::connections::OfflineFrame frame;
|
||||
frame.ParseFromString(serialized_frame.AsStringView());
|
||||
frame.ParseFromString(serialized_frame);
|
||||
frame.mutable_v1()->mutable_connection_request()->clear_connections_device();
|
||||
frame.mutable_v1()->mutable_connection_request()->clear_presence_device();
|
||||
ASSERT_FALSE(frame.v1().connection_request().has_connections_device());
|
||||
ASSERT_FALSE(frame.v1().connection_request().has_presence_device());
|
||||
// do a dummy write to get to the actual write.
|
||||
channel_pair.first->Write(ByteArray());
|
||||
channel_pair.first->Write(ByteArray(frame.SerializeAsString()));
|
||||
channel_pair.first->Write("");
|
||||
channel_pair.first->Write(frame.SerializeAsString());
|
||||
EXPECT_EQ(pcp_handler
|
||||
.OnIncomingConnection(
|
||||
client_.get(), ByteArray("remote endpoint"),
|
||||
@@ -2370,21 +2369,21 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithConnections) {
|
||||
ASSERT_TRUE(client_->IsListeningForIncomingConnections());
|
||||
ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get()));
|
||||
auto channel_pair = SetupConnection(Medium::BLUETOOTH);
|
||||
ByteArray serialized_frame = parser::ForConnectionRequestConnections(
|
||||
std::string serialized_frame = parser::ForConnectionRequestConnections(
|
||||
{}, {
|
||||
.local_endpoint_id = "ABCD",
|
||||
.local_endpoint_info = ByteArray("local endpoint"),
|
||||
});
|
||||
location::nearby::connections::OfflineFrame frame;
|
||||
frame.ParseFromString(serialized_frame.AsStringView());
|
||||
frame.ParseFromString(serialized_frame);
|
||||
frame.mutable_v1()
|
||||
->mutable_connection_request()
|
||||
->mutable_connections_device()
|
||||
->set_endpoint_id("ABCD");
|
||||
ASSERT_TRUE(frame.v1().connection_request().has_connections_device());
|
||||
// do a dummy write to get to the actual write.
|
||||
channel_pair.first->Write(ByteArray());
|
||||
channel_pair.first->Write(ByteArray(frame.SerializeAsString()));
|
||||
channel_pair.first->Write("");
|
||||
channel_pair.first->Write(frame.SerializeAsString());
|
||||
EXPECT_EQ(pcp_handler
|
||||
.OnIncomingConnection(
|
||||
client_.get(), ByteArray("remote endpoint"),
|
||||
@@ -2420,21 +2419,21 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithPresence) {
|
||||
ASSERT_TRUE(client_->IsListeningForIncomingConnections());
|
||||
ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get()));
|
||||
auto channel_pair = SetupConnection(Medium::BLUETOOTH);
|
||||
ByteArray serialized_frame = parser::ForConnectionRequestConnections(
|
||||
std::string serialized_frame = parser::ForConnectionRequestConnections(
|
||||
{}, {
|
||||
.local_endpoint_id = "ABCD",
|
||||
.local_endpoint_info = ByteArray("local endpoint"),
|
||||
});
|
||||
location::nearby::connections::OfflineFrame frame;
|
||||
frame.ParseFromString(serialized_frame.AsStringView());
|
||||
frame.ParseFromString(serialized_frame);
|
||||
frame.mutable_v1()
|
||||
->mutable_connection_request()
|
||||
->mutable_presence_device()
|
||||
->set_endpoint_id("ABCD");
|
||||
ASSERT_TRUE(frame.v1().connection_request().has_presence_device());
|
||||
// do a dummy write to get to the actual write.
|
||||
channel_pair.first->Write(ByteArray());
|
||||
channel_pair.first->Write(ByteArray(frame.SerializeAsString()));
|
||||
channel_pair.first->Write("");
|
||||
channel_pair.first->Write(frame.SerializeAsString());
|
||||
EXPECT_TRUE(pcp_handler
|
||||
.OnIncomingConnection(
|
||||
client_.get(), ByteArray("remote endpoint"),
|
||||
@@ -2469,21 +2468,21 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithConnections) {
|
||||
ASSERT_TRUE(client_->IsListeningForIncomingConnections());
|
||||
ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get()));
|
||||
auto channel_pair = SetupConnection(Medium::BLUETOOTH);
|
||||
ByteArray serialized_frame = parser::ForConnectionRequestConnections(
|
||||
std::string serialized_frame = parser::ForConnectionRequestConnections(
|
||||
{}, {
|
||||
.local_endpoint_id = "ABCD",
|
||||
.local_endpoint_info = ByteArray("local endpoint"),
|
||||
});
|
||||
location::nearby::connections::OfflineFrame frame;
|
||||
frame.ParseFromString(serialized_frame.AsStringView());
|
||||
frame.ParseFromString(serialized_frame);
|
||||
frame.mutable_v1()
|
||||
->mutable_connection_request()
|
||||
->mutable_connections_device()
|
||||
->set_endpoint_id("ABCD");
|
||||
ASSERT_TRUE(frame.v1().connection_request().has_connections_device());
|
||||
// do a dummy write to get to the actual write.
|
||||
channel_pair.first->Write(ByteArray());
|
||||
channel_pair.first->Write(ByteArray(frame.SerializeAsString()));
|
||||
channel_pair.first->Write("");
|
||||
channel_pair.first->Write(frame.SerializeAsString());
|
||||
EXPECT_TRUE(pcp_handler
|
||||
.OnIncomingConnection(
|
||||
client_.get(), ByteArray("remote endpoint"),
|
||||
@@ -2518,21 +2517,21 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithPresence) {
|
||||
ASSERT_TRUE(client_->IsListeningForIncomingConnections());
|
||||
ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get()));
|
||||
auto channel_pair = SetupConnection(Medium::BLUETOOTH);
|
||||
ByteArray serialized_frame = parser::ForConnectionRequestConnections(
|
||||
std::string serialized_frame = parser::ForConnectionRequestConnections(
|
||||
{}, {
|
||||
.local_endpoint_id = "ABCD",
|
||||
.local_endpoint_info = ByteArray("local endpoint"),
|
||||
});
|
||||
location::nearby::connections::OfflineFrame frame;
|
||||
frame.ParseFromString(serialized_frame.AsStringView());
|
||||
frame.ParseFromString(serialized_frame);
|
||||
frame.mutable_v1()
|
||||
->mutable_connection_request()
|
||||
->mutable_presence_device()
|
||||
->set_endpoint_id("ABCD");
|
||||
ASSERT_TRUE(frame.v1().connection_request().has_presence_device());
|
||||
// do a dummy write to get to the actual write.
|
||||
channel_pair.first->Write(ByteArray());
|
||||
channel_pair.first->Write(ByteArray(frame.SerializeAsString()));
|
||||
channel_pair.first->Write("");
|
||||
channel_pair.first->Write(frame.SerializeAsString());
|
||||
EXPECT_EQ(pcp_handler
|
||||
.OnIncomingConnection(
|
||||
client_.get(), ByteArray("remote endpoint"),
|
||||
@@ -2568,7 +2567,7 @@ TEST_F(BasePcpHandlerTest, IncomingConnectionFailsWithEmptyEndpointId) {
|
||||
ASSERT_TRUE(client_->IsListeningForIncomingConnections());
|
||||
ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(client_.get()));
|
||||
auto channel_pair = SetupConnection(Medium::BLUETOOTH);
|
||||
ByteArray serialized_frame = parser::ForConnectionRequestConnections(
|
||||
std::string serialized_frame = parser::ForConnectionRequestConnections(
|
||||
{}, {
|
||||
.local_endpoint_id = "",
|
||||
.local_endpoint_info = ByteArray("local endpoint"),
|
||||
@@ -2576,12 +2575,12 @@ TEST_F(BasePcpHandlerTest, IncomingConnectionFailsWithEmptyEndpointId) {
|
||||
// At this point the connection request doesn't have an endpoint ID field
|
||||
// set, so we do that here.
|
||||
location::nearby::connections::OfflineFrame frame;
|
||||
frame.ParseFromString(serialized_frame.AsStringView());
|
||||
frame.ParseFromString(serialized_frame);
|
||||
frame.mutable_v1()->mutable_connection_request()->set_endpoint_id("");
|
||||
ASSERT_TRUE(frame.v1().connection_request().has_endpoint_id());
|
||||
// do a dummy write to get to the actual write.
|
||||
channel_pair.first->Write(ByteArray());
|
||||
channel_pair.first->Write(ByteArray(frame.SerializeAsString()));
|
||||
channel_pair.first->Write("");
|
||||
channel_pair.first->Write(frame.SerializeAsString());
|
||||
absl::string_view expected_log = R"pb(
|
||||
event_type: CLIENT_SESSION
|
||||
client_session {
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#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"
|
||||
#include "internal/platform/mac_address.h"
|
||||
@@ -116,7 +115,7 @@ BluetoothBwuHandler::CreateUpgradedEndpointChannel(
|
||||
return {std::move(channel)};
|
||||
}
|
||||
|
||||
ByteArray BluetoothBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string BluetoothBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) {
|
||||
MacAddress mac_address = bluetooth_medium_.GetAddress();
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/medium_selector.h"
|
||||
#include "internal/platform/bluetooth_classic.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -66,7 +65,7 @@ class BluetoothBwuHandler : public BaseBwuHandler {
|
||||
const std::string& endpoint_id) final {}
|
||||
|
||||
// BaseBwuHandler implementation:
|
||||
ByteArray HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) final;
|
||||
void HandleRevertInitiatorStateForService(
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
@@ -23,7 +24,6 @@
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/expected.h"
|
||||
@@ -83,11 +83,11 @@ TEST_F(BluetoothBwuTest, SoftAPBWUInit_STACreateEndpointChannel) {
|
||||
// client_1 works as Bluetooth Server Device
|
||||
SingleThreadExecutor server_executor;
|
||||
server_executor.Execute([&]() {
|
||||
ByteArray upgrade_path_available_frame =
|
||||
std::string upgrade_path_available_frame =
|
||||
handler_1->InitializeUpgradedMediumForEndpoint(&client_1,
|
||||
/*service_id=*/"A",
|
||||
/*endpoint_id=*/"1");
|
||||
EXPECT_FALSE(upgrade_path_available_frame.Empty());
|
||||
EXPECT_FALSE(upgrade_path_available_frame.empty());
|
||||
|
||||
upgrade_frame = parser::FromBytes(upgrade_path_available_frame);
|
||||
start_latch.CountDown();
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -53,7 +52,7 @@ class BwuHandler {
|
||||
// that hasn't already been done), and returns a serialized UpgradePathInfo
|
||||
// that can be sent to the Responder.
|
||||
// @BwuHandlerThread
|
||||
virtual ByteArray InitializeUpgradedMediumForEndpoint(
|
||||
virtual std::string InitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& service_id,
|
||||
const std::string& endpoint_id) = 0;
|
||||
|
||||
|
||||
@@ -47,7 +47,6 @@
|
||||
#include "connections/implementation/wifi_hotspot_bwu_handler.h"
|
||||
#include "connections/implementation/wifi_lan_bwu_handler.h"
|
||||
#include "connections/medium_selector.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/cancelable_alarm.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/expected.h"
|
||||
@@ -341,12 +340,12 @@ void BwuManager::InitiateBwuForEndpoint(ClientProxy* client,
|
||||
}
|
||||
|
||||
std::string service_id = channel->GetServiceId();
|
||||
ByteArray bytes = handler->InitializeUpgradedMediumForEndpoint(
|
||||
std::string bytes = handler->InitializeUpgradedMediumForEndpoint(
|
||||
client, service_id, endpoint_id);
|
||||
|
||||
// Because we grab the endpointChannel first thing, it is possible the
|
||||
// endpointChannel is stale by the time we attempt to write over it.
|
||||
if (bytes.Empty()) {
|
||||
if (bytes.empty()) {
|
||||
LOG(ERROR) << "BwuManager couldn't complete the upgrade for endpoint "
|
||||
<< endpoint_id << " to medium "
|
||||
<< location::nearby::proto::connections::Medium_Name(
|
||||
@@ -1138,7 +1137,7 @@ bool BwuManager::ReadClientIntroductionFrame(
|
||||
auto data = channel->Read();
|
||||
timeout_alarm.Cancel();
|
||||
if (!data.ok()) return false;
|
||||
auto transfer(parser::FromBytes(data.result()));
|
||||
auto transfer(parser::FromBytes(data.result().AsStringView()));
|
||||
if (!transfer.ok()) {
|
||||
LOG(ERROR) << "In ReadClientIntroductionFrame, attempted to read a "
|
||||
"ClientIntroductionFrame from EndpointChannel "
|
||||
@@ -1189,7 +1188,7 @@ bool BwuManager::ReadClientIntroductionAckFrame(EndpointChannel* channel) {
|
||||
auto data = channel->Read();
|
||||
timeout_alarm.Cancel();
|
||||
if (!data.ok()) return false;
|
||||
auto transfer(parser::FromBytes(data.result()));
|
||||
auto transfer(parser::FromBytes(data.result().AsStringView()));
|
||||
if (!transfer.ok()) return false;
|
||||
OfflineFrame frame = transfer.result();
|
||||
if (!frame.has_v1() || !frame.v1().has_bandwidth_upgrade_negotiation())
|
||||
|
||||
@@ -924,12 +924,12 @@ TEST_F(BwuManagerTest, InitiateBwu_Revert_OnDisconnect_WifiDirect) {
|
||||
OfflineFrame frame;
|
||||
CreateInitialEndpoint(&client_, kServiceIdA, kEndpointId1, Medium::BLUETOOTH);
|
||||
|
||||
ByteArray bytes = parser::ForBwuWifiDirectPathAvailable(
|
||||
std::string bytes = parser::ForBwuWifiDirectPathAvailable(
|
||||
/*ssid=*/"", /*password=*/"", /*port=*/2143,
|
||||
/*frequency=*/2412, /*supports_disabling_encryption=*/false,
|
||||
/*gateway=*/"123.234.23.1", /*service_name=*/"NC-WifiDirectTest",
|
||||
/*pin=*/"b592f7d3");
|
||||
frame.ParseFromString(std::string(bytes));
|
||||
frame.ParseFromString(bytes);
|
||||
|
||||
::nearby::connections::V1Frame* v1_frame = frame.mutable_v1();
|
||||
::nearby::connections::BandwidthUpgradeNegotiationFrame* sub_frame =
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -33,7 +32,7 @@ void ConnectionsAuthenticationTransport::WriteMessage(
|
||||
absl::string_view message) const {
|
||||
// channel_ should never be null.
|
||||
CHECK(channel_ != nullptr);
|
||||
channel_->Write(ByteArray(message.data(), message.size()));
|
||||
channel_->Write(message);
|
||||
}
|
||||
|
||||
std::string ConnectionsAuthenticationTransport::ReadMessage() const {
|
||||
|
||||
@@ -40,7 +40,7 @@ class MockEndpointChannel : public EndpointChannel {
|
||||
public:
|
||||
MOCK_METHOD(ExceptionOr<ByteArray>, Read, (), (override));
|
||||
MOCK_METHOD(ExceptionOr<ByteArray>, Read, (PacketMetaData&), (override));
|
||||
MOCK_METHOD(Exception, Write, (const ByteArray& data), (override));
|
||||
MOCK_METHOD(Exception, Write, (absl::string_view data), (override));
|
||||
MOCK_METHOD(Exception, Write, (absl::string_view data, PacketMetaData&),
|
||||
(override));
|
||||
MOCK_METHOD(void, Close, (), (override));
|
||||
@@ -87,8 +87,8 @@ class MockEndpointChannel : public EndpointChannel {
|
||||
TEST(ConnectionsAuthenticationTransportTest, TestWriteMessage) {
|
||||
MockEndpointChannel channel;
|
||||
ConnectionsAuthenticationTransport transport(channel);
|
||||
EXPECT_CALL(channel, Write(_)).WillOnce([&channel](const ByteArray& data) {
|
||||
channel.messages_.push_back(data.string_data());
|
||||
EXPECT_CALL(channel, Write(_)).WillOnce([&channel](absl::string_view data) {
|
||||
channel.messages_.push_back(std::string(data));
|
||||
return Exception{
|
||||
.value = Exception::Value::kSuccess,
|
||||
};
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "connections/implementation/encryption_runner.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -22,7 +21,6 @@
|
||||
|
||||
#include "securegcm/ukey2_handshake.h"
|
||||
#include "absl/strings/ascii.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
@@ -139,8 +137,7 @@ class ServerRunnable final {
|
||||
return;
|
||||
}
|
||||
|
||||
Exception write_exception =
|
||||
channel_->Write(ByteArray(std::move(*server_init)));
|
||||
Exception write_exception = channel_->Write(*server_init);
|
||||
if (!write_exception.Ok()) {
|
||||
LogException();
|
||||
HandleHandshakeOrIoException(&timeout_alarm);
|
||||
@@ -198,7 +195,7 @@ class ServerRunnable final {
|
||||
void HandleAlertException(
|
||||
const securegcm::UKey2Handshake::ParseResult& parse_result) const {
|
||||
Exception write_exception =
|
||||
channel_->Write(ByteArray(*parse_result.alert_to_send));
|
||||
channel_->Write(*parse_result.alert_to_send);
|
||||
if (!write_exception.Ok()) {
|
||||
LOG(WARNING) << "In StartServer(), client " << client_->GetClientId()
|
||||
<< " failed to pass the alert error message to endpoint(id="
|
||||
@@ -251,7 +248,7 @@ class ClientRunnable final {
|
||||
return;
|
||||
}
|
||||
|
||||
Exception write_init_exception = channel_->Write(ByteArray(*client_init));
|
||||
Exception write_init_exception = channel_->Write(*client_init);
|
||||
if (!write_init_exception.Ok()) {
|
||||
LogException();
|
||||
HandleHandshakeOrIoException(&timeout_alarm);
|
||||
@@ -298,7 +295,7 @@ class ClientRunnable final {
|
||||
}
|
||||
|
||||
Exception write_finish_exception =
|
||||
channel_->Write(ByteArray(*client_finish));
|
||||
channel_->Write(*client_finish);
|
||||
if (!write_finish_exception.Ok()) {
|
||||
LogException();
|
||||
HandleHandshakeOrIoException(&timeout_alarm);
|
||||
@@ -330,8 +327,7 @@ class ClientRunnable final {
|
||||
|
||||
void HandleAlertException(
|
||||
const securegcm::UKey2Handshake::ParseResult& parse_result) const {
|
||||
Exception write_exception =
|
||||
channel_->Write(ByteArray(*parse_result.alert_to_send));
|
||||
Exception write_exception = channel_->Write(*parse_result.alert_to_send);
|
||||
if (!write_exception.Ok()) {
|
||||
LOG(WARNING) << "In StartClient(), client " << client_->GetClientId()
|
||||
<< " failed to pass the alert error message to endpoint(id="
|
||||
|
||||
@@ -56,14 +56,13 @@ class FakeEndpointChannel : public EndpointChannel {
|
||||
read_timestamp_ = SystemClock::ElapsedRealtime();
|
||||
return in_ ? in_->Read(kChunkSize) : ExceptionOr<ByteArray>{Exception::kIo};
|
||||
}
|
||||
Exception Write(const ByteArray& data) override {
|
||||
Exception Write(absl::string_view data) override {
|
||||
write_timestamp_ = SystemClock::ElapsedRealtime();
|
||||
return out_ ? out_->Write(data.AsStringView()) : Exception{Exception::kIo};
|
||||
return out_ ? out_->Write(data) : Exception{Exception::kIo};
|
||||
}
|
||||
Exception Write(absl::string_view data,
|
||||
PacketMetaData& packet_meta_data) override {
|
||||
write_timestamp_ = SystemClock::ElapsedRealtime();
|
||||
return out_ ? out_->Write(data) : Exception{Exception::kIo};
|
||||
return Write(data);
|
||||
}
|
||||
void Close() override {
|
||||
if (in_) in_->Close();
|
||||
|
||||
@@ -43,7 +43,7 @@ class EndpointChannel {
|
||||
|
||||
virtual ExceptionOr<ByteArray> Read(PacketMetaData& packet_meta_data) = 0;
|
||||
|
||||
virtual Exception Write(const ByteArray& data) = 0; // throws Exception::IO
|
||||
virtual Exception Write(absl::string_view data) = 0; // throws Exception::IO
|
||||
|
||||
virtual Exception Write(
|
||||
absl::string_view data,
|
||||
|
||||
@@ -227,12 +227,12 @@ TEST(BaseEndpointChannelManagerTest, RegisterChannelEncryptedReadwrite) {
|
||||
EXPECT_EQ(channel_a_raw->GetType(), "ENCRYPTED_BLUETOOTH");
|
||||
EXPECT_EQ(channel_b_raw->GetType(), "ENCRYPTED_BLUETOOTH");
|
||||
|
||||
ByteArray tx_message{"data message"};
|
||||
absl::string_view tx_message = "data message";
|
||||
channel_a_raw->Write(tx_message);
|
||||
ByteArray rx_message = std::move(channel_b_raw->Read().result());
|
||||
|
||||
// Verify expectations.
|
||||
EXPECT_EQ(rx_message, tx_message);
|
||||
EXPECT_EQ(rx_message.AsStringView(), tx_message);
|
||||
{
|
||||
absl::MutexLock lock(mutex);
|
||||
std::string message{tx_message};
|
||||
|
||||
@@ -207,7 +207,7 @@ ExceptionOr<OfflineFrame> EndpointManager::TryDecryptFrame(
|
||||
if (decrypted.ok()) {
|
||||
VLOG(1) << "Message decrypted after "
|
||||
<< SystemClock::ElapsedRealtime() - start_time;
|
||||
return parser::FromBytes(decrypted.result());
|
||||
return parser::FromBytes(decrypted.result().AsStringView());
|
||||
}
|
||||
if (decrypted.exception() == Exception::kExecution) {
|
||||
return decrypted.exception();
|
||||
@@ -245,7 +245,8 @@ ExceptionOr<bool> EndpointManager::HandleData(
|
||||
}
|
||||
return ExceptionOr<bool>(bytes.exception());
|
||||
}
|
||||
ExceptionOr<OfflineFrame> wrapped_frame = parser::FromBytes(bytes.result());
|
||||
ExceptionOr<OfflineFrame> wrapped_frame =
|
||||
parser::FromBytes(bytes.result().AsStringView());
|
||||
if (!wrapped_frame.ok() && try_decrypting) {
|
||||
// Workaround for a race condition where the remote party has sent an
|
||||
// encrypted message but our end was still configured as unencrypted when
|
||||
@@ -668,7 +669,7 @@ std::vector<std::string> EndpointManager::SendPayloadChunk(
|
||||
const PayloadTransferFrame::PayloadChunk& payload_chunk,
|
||||
const std::vector<std::string>& endpoint_ids,
|
||||
PacketMetaData& packet_meta_data) {
|
||||
ByteArray bytes =
|
||||
std::string bytes =
|
||||
parser::ForDataPayloadTransfer(payload_header, payload_chunk);
|
||||
|
||||
return SendTransferFrameBytes(
|
||||
@@ -743,7 +744,7 @@ std::vector<std::string> EndpointManager::SendControlMessage(
|
||||
const PayloadTransferFrame::PayloadHeader& header,
|
||||
const PayloadTransferFrame::ControlMessage& control,
|
||||
const std::vector<std::string>& endpoint_ids) {
|
||||
ByteArray bytes = parser::ForControlPayloadTransfer(header, control);
|
||||
std::string bytes = parser::ForControlPayloadTransfer(header, control);
|
||||
PacketMetaData packet_meta_data;
|
||||
|
||||
return SendTransferFrameBytes(
|
||||
@@ -920,7 +921,7 @@ CountDownLatch EndpointManager::NotifyFrameProcessorsOnEndpointDisconnect(
|
||||
|
||||
std::vector<std::string> EndpointManager::SendPayloadAck(
|
||||
std::int64_t payload_id, const std::vector<std::string>& endpoint_ids) {
|
||||
ByteArray bytes = parser::ForPayloadAckPayloadTransfer(payload_id);
|
||||
std::string bytes = parser::ForPayloadAckPayloadTransfer(payload_id);
|
||||
PacketMetaData packet_meta_data;
|
||||
|
||||
return SendTransferFrameBytes(
|
||||
@@ -932,7 +933,7 @@ std::vector<std::string> EndpointManager::SendPayloadAck(
|
||||
}
|
||||
|
||||
std::vector<std::string> EndpointManager::SendTransferFrameBytes(
|
||||
const std::vector<std::string>& endpoint_ids, const ByteArray& bytes,
|
||||
const std::vector<std::string>& endpoint_ids, const std::string& bytes,
|
||||
std::int64_t payload_id, std::int64_t offset,
|
||||
const std::string& packet_type, PacketMetaData& packet_meta_data) {
|
||||
std::vector<std::string> failed_endpoint_ids;
|
||||
@@ -954,7 +955,7 @@ std::vector<std::string> EndpointManager::SendTransferFrameBytes(
|
||||
}
|
||||
|
||||
Exception write_exception =
|
||||
channel->Write(bytes.AsStringView(), packet_meta_data);
|
||||
channel->Write(bytes, packet_meta_data);
|
||||
if (!write_exception.Ok()) {
|
||||
failed_endpoint_ids.push_back(endpoint_id);
|
||||
LOG(INFO) << "Failed to send packet; endpoint_id=" << endpoint_id;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#define CORE_INTERNAL_ENDPOINT_MANAGER_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -24,7 +23,6 @@
|
||||
|
||||
#include "absl/base/thread_annotations.h"
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "connections/implementation/analytics/packet_meta_data.h"
|
||||
@@ -283,7 +281,7 @@ class EndpointManager {
|
||||
|
||||
std::vector<std::string> SendTransferFrameBytes(
|
||||
const std::vector<std::string>& endpoint_ids,
|
||||
const ByteArray& payload_transfer_frame_bytes, std::int64_t payload_id,
|
||||
const std::string& payload_transfer_frame_bytes, std::int64_t payload_id,
|
||||
std::int64_t offset, const std::string& packet_type,
|
||||
analytics::PacketMetaData& packet_meta_data);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class MockEndpointChannel : public EndpointChannel {
|
||||
MOCK_METHOD(ExceptionOr<ByteArray>, Read, (), (override));
|
||||
MOCK_METHOD(ExceptionOr<ByteArray>, Read, (PacketMetaData & packet_meta_data),
|
||||
(override));
|
||||
MOCK_METHOD(Exception, Write, (const ByteArray& data), (override));
|
||||
MOCK_METHOD(Exception, Write, (absl::string_view data), (override));
|
||||
MOCK_METHOD(Exception, Write,
|
||||
(absl::string_view data, PacketMetaData& packet_meta_data),
|
||||
(override));
|
||||
@@ -277,11 +277,12 @@ TEST_F(EndpointManagerTest, RegisterFrameProcessorWorks) {
|
||||
0 /*keep_alive_interval_millis*/,
|
||||
0 /*keep_alive_timeout_millis*/};
|
||||
|
||||
auto read_data = parser::ForConnectionRequestConnections({}, connection_info);
|
||||
std::string read_data =
|
||||
parser::ForConnectionRequestConnections({}, connection_info);
|
||||
EXPECT_CALL(*connect_request, OnIncomingFrame);
|
||||
EXPECT_CALL(*connect_request, OnEndpointDisconnect);
|
||||
EXPECT_CALL(*endpoint_channel, Read(_))
|
||||
.WillOnce(Return(ExceptionOr<ByteArray>(read_data)))
|
||||
.WillOnce(Return(ExceptionOr<ByteArray>(ByteArray(read_data))))
|
||||
.WillRepeatedly(Return(ExceptionOr<ByteArray>(Exception::kIo)));
|
||||
EXPECT_CALL(*endpoint_channel, Write(_))
|
||||
.WillRepeatedly(Return(Exception{Exception::kSuccess}));
|
||||
@@ -429,7 +430,9 @@ class EndpointManagerFuzzTest
|
||||
|
||||
auto InvalidPayloadDomain() {
|
||||
return Filter(
|
||||
[](ByteArray payload) { return !parser::FromBytes(payload).ok(); },
|
||||
[](ByteArray payload) {
|
||||
return !parser::FromBytes(payload.AsStringView()).ok();
|
||||
},
|
||||
Map([](std::string payloadString) { return ByteArray(payloadString); },
|
||||
String()));
|
||||
}
|
||||
@@ -461,7 +464,7 @@ TEST_F(EndpointManagerTest, TryDecrypt) {
|
||||
std::vector<Medium>{Medium::BLE} /*supported_mediums*/,
|
||||
0 /*keep_alive_interval_millis*/,
|
||||
0 /*keep_alive_timeout_millis*/};
|
||||
ByteArray decrypted_data =
|
||||
std::string decrypted_data =
|
||||
parser::ForConnectionRequestConnections({}, connection_info);
|
||||
EXPECT_CALL(*connect_request, OnIncomingFrame);
|
||||
EXPECT_CALL(*connect_request, OnEndpointDisconnect);
|
||||
@@ -470,7 +473,7 @@ TEST_F(EndpointManagerTest, TryDecrypt) {
|
||||
.WillRepeatedly(Return(ExceptionOr<ByteArray>(Exception::kIo)));
|
||||
EXPECT_CALL(*endpoint_channel, TryDecrypt(Eq(payload)))
|
||||
.WillOnce(Return(ExceptionOr<ByteArray>(Exception::kFailed)))
|
||||
.WillOnce(Return(ExceptionOr<ByteArray>(decrypted_data)));
|
||||
.WillOnce(Return(ExceptionOr<ByteArray>(ByteArray(decrypted_data))));
|
||||
EXPECT_CALL(*endpoint_channel, Write(_))
|
||||
.WillRepeatedly(Return(Exception{Exception::kSuccess}));
|
||||
em_.RegisterFrameProcessor(V1Frame::CONNECTION_REQUEST,
|
||||
|
||||
@@ -87,9 +87,9 @@ class FakeBwuHandler : public BaseBwuHandler {
|
||||
medium_, *handle_initialize_calls_[initialize_call_index].service_id);
|
||||
FakeEndpointChannel* upgraded_channel_raw = upgraded_channel.get();
|
||||
upgraded_channel->set_read_output(
|
||||
ExceptionOr<ByteArray>(parser::ForBwuIntroduction(
|
||||
ExceptionOr<ByteArray>(ByteArray(parser::ForBwuIntroduction(
|
||||
*handle_initialize_calls_[initialize_call_index].endpoint_id,
|
||||
false /* supports_disabling_encryption */)));
|
||||
false /* supports_disabling_encryption */))));
|
||||
auto connection = std::make_unique<IncomingSocketConnection>();
|
||||
connection->channel = std::move(upgraded_channel);
|
||||
|
||||
@@ -133,7 +133,7 @@ class FakeBwuHandler : public BaseBwuHandler {
|
||||
}
|
||||
|
||||
// BaseBwuHandler:
|
||||
ByteArray HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) final {
|
||||
handle_initialize_calls_.push_back({.client = client,
|
||||
@@ -188,7 +188,7 @@ class FakeBwuHandler : public BaseBwuHandler {
|
||||
case location::nearby::proto::connections::BLE_L2CAP:
|
||||
case location::nearby::proto::connections::USB:
|
||||
case location::nearby::proto::connections::AWDL:
|
||||
return ByteArray{};
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class FakeEndpointChannel : public EndpointChannel {
|
||||
read_timestamp_ = SystemClock::ElapsedRealtime();
|
||||
return read_output_;
|
||||
}
|
||||
Exception Write(const ByteArray& data) override {
|
||||
Exception Write(absl::string_view data) override {
|
||||
write_timestamp_ = SystemClock::ElapsedRealtime();
|
||||
return write_output_;
|
||||
}
|
||||
|
||||
@@ -25,10 +25,9 @@ cc_test(
|
||||
tags = ["componentid:148515"],
|
||||
deps = [
|
||||
"//connections/implementation:internal",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform/implementation/g3",
|
||||
"//testing/fuzzing:fuzztest",
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_absl//absl/strings:string_view",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -12,13 +12,11 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
nearby::ByteArray byte_array;
|
||||
byte_array.SetData(reinterpret_cast<const char*>(data), size);
|
||||
|
||||
absl::string_view byte_array(reinterpret_cast<const char*>(data), size);
|
||||
nearby::connections::parser::FromBytes(byte_array);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -192,7 +192,7 @@ TEST(MultiplexSocketTest, CreateIncomingSocketSuccess) {
|
||||
SingleThreadExecutor executor;
|
||||
FakeSocket* socket = fake_socket_ptr.get();
|
||||
executor.Execute([socket]() {
|
||||
ByteArray connection_req_frame = parser::ForConnectionRequestConnections(
|
||||
std::string connection_req_frame = parser::ForConnectionRequestConnections(
|
||||
{}, {
|
||||
.local_endpoint_id = "endpoint1",
|
||||
.local_endpoint_info = ByteArray("endpoint1 info"),
|
||||
@@ -200,7 +200,7 @@ TEST(MultiplexSocketTest, CreateIncomingSocketSuccess) {
|
||||
auto& writer = socket->writer_1_;
|
||||
LOG(INFO) << "writer_1_ Write start";
|
||||
Base64Utils::WriteInt(writer.get(), connection_req_frame.size());
|
||||
writer->Write(connection_req_frame.AsStringView());
|
||||
writer->Write(connection_req_frame);
|
||||
writer->Flush();
|
||||
LOG(INFO) << "writer_1_ Write end";
|
||||
});
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "connections/connection_options.h"
|
||||
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
|
||||
#include "connections/implementation/internal_payload.h"
|
||||
@@ -27,7 +28,6 @@
|
||||
#include "connections/medium_selector.h"
|
||||
#include "connections/status.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/mac_address.h"
|
||||
@@ -49,19 +49,12 @@ using ::location::nearby::connections::OsInfo;
|
||||
using ::location::nearby::connections::PayloadTransferFrame;
|
||||
using ::location::nearby::connections::V1Frame;
|
||||
|
||||
ByteArray ToBytes(OfflineFrame&& frame) {
|
||||
ByteArray bytes(frame.ByteSizeLong());
|
||||
frame.set_version(OfflineFrame::V1);
|
||||
frame.SerializeToArray(bytes.data(), bytes.size());
|
||||
return bytes;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
ExceptionOrOfflineFrame FromBytes(const ByteArray& bytes) {
|
||||
ExceptionOrOfflineFrame FromBytes(absl::string_view bytes) {
|
||||
OfflineFrame frame;
|
||||
|
||||
if (frame.ParseFromString(std::string(bytes))) {
|
||||
if (frame.ParseFromString(bytes)) {
|
||||
Exception validation_exception = EnsureValidOfflineFrame(frame);
|
||||
if (validation_exception.Raised()) {
|
||||
return ExceptionOrOfflineFrame(validation_exception);
|
||||
@@ -80,7 +73,7 @@ V1Frame::FrameType GetFrameType(const OfflineFrame& frame) {
|
||||
return V1Frame::UNKNOWN_FRAME_TYPE;
|
||||
}
|
||||
|
||||
ByteArray ForConnectionRequestConnections(
|
||||
std::string ForConnectionRequestConnections(
|
||||
const location::nearby::connections::ConnectionsDevice&
|
||||
proto_connections_device,
|
||||
const ConnectionInfo& connection_info) {
|
||||
@@ -139,10 +132,10 @@ ByteArray ForConnectionRequestConnections(
|
||||
connection_info.keep_alive_timeout_millis);
|
||||
}
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForConnectionRequestPresence(
|
||||
std::string ForConnectionRequestPresence(
|
||||
const location::nearby::connections::PresenceDevice& proto_presence_device,
|
||||
const ConnectionInfo& connection_info) {
|
||||
OfflineFrame frame;
|
||||
@@ -184,10 +177,10 @@ ByteArray ForConnectionRequestPresence(
|
||||
connection_info.keep_alive_timeout_millis);
|
||||
}
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForConnectionResponse(std::int32_t status, const OsInfo& os_info,
|
||||
std::string ForConnectionResponse(std::int32_t status, const OsInfo& os_info,
|
||||
std::int32_t multiplex_socket_bitmask) {
|
||||
OfflineFrame frame;
|
||||
|
||||
@@ -210,10 +203,10 @@ ByteArray ForConnectionResponse(std::int32_t status, const OsInfo& os_info,
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kSafeToDisconnectVersion));
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForDataPayloadTransfer(
|
||||
std::string ForDataPayloadTransfer(
|
||||
const PayloadTransferFrame::PayloadHeader& header,
|
||||
const PayloadTransferFrame::PayloadChunk& chunk) {
|
||||
OfflineFrame frame;
|
||||
@@ -226,10 +219,10 @@ ByteArray ForDataPayloadTransfer(
|
||||
*sub_frame->mutable_payload_header() = header;
|
||||
*sub_frame->mutable_payload_chunk() = chunk;
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForControlPayloadTransfer(
|
||||
std::string ForControlPayloadTransfer(
|
||||
const PayloadTransferFrame::PayloadHeader& header,
|
||||
const PayloadTransferFrame::ControlMessage& control) {
|
||||
OfflineFrame frame;
|
||||
@@ -242,10 +235,10 @@ ByteArray ForControlPayloadTransfer(
|
||||
*sub_frame->mutable_payload_header() = header;
|
||||
*sub_frame->mutable_control_message() = control;
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForPayloadAckPayloadTransfer(std::int64_t payload_id) {
|
||||
std::string ForPayloadAckPayloadTransfer(std::int64_t payload_id) {
|
||||
OfflineFrame frame;
|
||||
|
||||
frame.set_version(OfflineFrame::V1);
|
||||
@@ -259,10 +252,10 @@ ByteArray ForPayloadAckPayloadTransfer(std::int64_t payload_id) {
|
||||
header.set_total_size(InternalPayload::kIndeterminateSize);
|
||||
*sub_frame->mutable_payload_header() = header;
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForBwuWifiHotspotPathAvailable(
|
||||
std::string ForBwuWifiHotspotPathAvailable(
|
||||
BandwidthUpgradeNegotiationFrame::UpgradePathInfo::WifiHotspotCredentials
|
||||
credentials,
|
||||
bool supports_disabling_encryption) {
|
||||
@@ -282,10 +275,10 @@ ByteArray ForBwuWifiHotspotPathAvailable(
|
||||
auto* wifi_hotspot_credentials =
|
||||
upgrade_path_info->mutable_wifi_hotspot_credentials();
|
||||
*wifi_hotspot_credentials = std::move(credentials);
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForBwuWifiLanPathAvailable(
|
||||
std::string ForBwuWifiLanPathAvailable(
|
||||
const std::vector<ServiceAddress>& addresses) {
|
||||
OfflineFrame frame;
|
||||
|
||||
@@ -314,10 +307,10 @@ ByteArray ForBwuWifiLanPathAvailable(
|
||||
VLOG(1) << "ForBwuWifiLanPathAvailable: " << address;
|
||||
}
|
||||
}
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForBwuAwdlPathAvailable(const std::string& service_name,
|
||||
std::string ForBwuAwdlPathAvailable(const std::string& service_name,
|
||||
const std::string& service_type,
|
||||
const std::string& password,
|
||||
bool supports_disabling_encryption) {
|
||||
@@ -339,10 +332,10 @@ ByteArray ForBwuAwdlPathAvailable(const std::string& service_name,
|
||||
awdl_socket->set_service_type(service_type);
|
||||
awdl_socket->set_password(password);
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForBwuWifiAwarePathAvailable(const std::string& service_id,
|
||||
std::string ForBwuWifiAwarePathAvailable(const std::string& service_id,
|
||||
const std::string& service_info,
|
||||
const std::string& password,
|
||||
bool supports_disabling_encryption) {
|
||||
@@ -365,10 +358,10 @@ ByteArray ForBwuWifiAwarePathAvailable(const std::string& service_id,
|
||||
wifi_aware_credentials->set_service_info(service_info);
|
||||
if (!password.empty()) wifi_aware_credentials->set_password(password);
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForBwuWifiDirectPathAvailable(
|
||||
std::string ForBwuWifiDirectPathAvailable(
|
||||
const std::string& ssid, const std::string& password, std::int32_t port,
|
||||
std::int32_t frequency, bool supports_disabling_encryption,
|
||||
const std::string& gateway, const std::string& service_name,
|
||||
@@ -396,10 +389,10 @@ ByteArray ForBwuWifiDirectPathAvailable(
|
||||
wifi_direct_credentials->set_service_name(service_name);
|
||||
wifi_direct_credentials->set_pin(pin);
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForBwuBluetoothPathAvailable(const std::string& service_id,
|
||||
std::string ForBwuBluetoothPathAvailable(const std::string& service_id,
|
||||
MacAddress mac_address) {
|
||||
OfflineFrame frame;
|
||||
|
||||
@@ -417,10 +410,10 @@ ByteArray ForBwuBluetoothPathAvailable(const std::string& service_id,
|
||||
bluetooth_credentials->set_mac_address(mac_address.ToString());
|
||||
bluetooth_credentials->set_service_name(service_id);
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForBwuWebrtcPathAvailable(const std::string& peer_id,
|
||||
std::string ForBwuWebrtcPathAvailable(const std::string& peer_id,
|
||||
const LocationHint& location_hint) {
|
||||
OfflineFrame frame;
|
||||
|
||||
@@ -438,10 +431,10 @@ ByteArray ForBwuWebrtcPathAvailable(const std::string& peer_id,
|
||||
auto* local_location_hint = webrtc_credentials->mutable_location_hint();
|
||||
*local_location_hint = location_hint;
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForBwuLastWrite() {
|
||||
std::string ForBwuLastWrite() {
|
||||
OfflineFrame frame;
|
||||
|
||||
frame.set_version(OfflineFrame::V1);
|
||||
@@ -451,10 +444,10 @@ ByteArray ForBwuLastWrite() {
|
||||
sub_frame->set_event_type(
|
||||
BandwidthUpgradeNegotiationFrame::LAST_WRITE_TO_PRIOR_CHANNEL);
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForBwuSafeToClose() {
|
||||
std::string ForBwuSafeToClose() {
|
||||
OfflineFrame frame;
|
||||
|
||||
frame.set_version(OfflineFrame::V1);
|
||||
@@ -464,10 +457,10 @@ ByteArray ForBwuSafeToClose() {
|
||||
sub_frame->set_event_type(
|
||||
BandwidthUpgradeNegotiationFrame::SAFE_TO_CLOSE_PRIOR_CHANNEL);
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForBwuIntroduction(const std::string& endpoint_id,
|
||||
std::string ForBwuIntroduction(const std::string& endpoint_id,
|
||||
bool supports_disabling_encryption) {
|
||||
OfflineFrame frame;
|
||||
|
||||
@@ -482,10 +475,10 @@ ByteArray ForBwuIntroduction(const std::string& endpoint_id,
|
||||
client_introduction->set_supports_disabling_encryption(
|
||||
supports_disabling_encryption);
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForBwuIntroductionAck() {
|
||||
std::string ForBwuIntroductionAck() {
|
||||
OfflineFrame frame;
|
||||
|
||||
frame.set_version(OfflineFrame::V1);
|
||||
@@ -495,10 +488,10 @@ ByteArray ForBwuIntroductionAck() {
|
||||
sub_frame->set_event_type(
|
||||
BandwidthUpgradeNegotiationFrame::CLIENT_INTRODUCTION_ACK);
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForBwuFailure(const UpgradePathInfo& info) {
|
||||
std::string ForBwuFailure(const UpgradePathInfo& info) {
|
||||
OfflineFrame frame;
|
||||
|
||||
frame.set_version(OfflineFrame::V1);
|
||||
@@ -511,10 +504,10 @@ ByteArray ForBwuFailure(const UpgradePathInfo& info) {
|
||||
|
||||
*sub_frame->mutable_upgrade_path_info() = info;
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForBwuPathRequest(const std::vector<Medium>& mediums,
|
||||
std::string ForBwuPathRequest(const std::vector<Medium>& mediums,
|
||||
const MediumRole& medium_role) {
|
||||
OfflineFrame frame;
|
||||
|
||||
@@ -533,10 +526,10 @@ ByteArray ForBwuPathRequest(const std::vector<Medium>& mediums,
|
||||
upgrade_path_request->mutable_medium_meta_data()->mutable_medium_role();
|
||||
role->MergeFrom(medium_role);
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForKeepAlive() {
|
||||
std::string ForKeepAlive() {
|
||||
OfflineFrame frame;
|
||||
|
||||
frame.set_version(OfflineFrame::V1);
|
||||
@@ -544,10 +537,10 @@ ByteArray ForKeepAlive() {
|
||||
v1_frame->set_type(V1Frame::KEEP_ALIVE);
|
||||
v1_frame->mutable_keep_alive();
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForKeepAlive(bool ack, uint32_t seq_num) {
|
||||
std::string ForKeepAlive(bool ack, uint32_t seq_num) {
|
||||
OfflineFrame frame;
|
||||
|
||||
frame.set_version(OfflineFrame::V1);
|
||||
@@ -556,10 +549,10 @@ ByteArray ForKeepAlive(bool ack, uint32_t seq_num) {
|
||||
KeepAliveFrame* keep_alive = v1_frame->mutable_keep_alive();
|
||||
keep_alive->set_ack(ack);
|
||||
keep_alive->set_seq_num(seq_num);
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
ByteArray ForDisconnection(bool request_safe_to_disconnect,
|
||||
std::string ForDisconnection(bool request_safe_to_disconnect,
|
||||
bool ack_safe_to_disconnect) {
|
||||
OfflineFrame frame;
|
||||
|
||||
@@ -570,7 +563,7 @@ ByteArray ForDisconnection(bool request_safe_to_disconnect,
|
||||
disconnection->set_request_safe_to_disconnect(request_safe_to_disconnect);
|
||||
disconnection->set_ack_safe_to_disconnect(ack_safe_to_disconnect);
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
return frame.SerializeAsString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "connections/connection_options.h"
|
||||
#include "connections/implementation/proto/offline_wire_formats.pb.h"
|
||||
#include "connections/medium_selector.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/mac_address.h"
|
||||
#include "internal/platform/service_address.h"
|
||||
@@ -43,7 +43,7 @@ using WifiDirectAuthType =
|
||||
// Returns OfflineFrame if parser was able to understand it, or
|
||||
// Exception::kInvalidProtocolBuffer, if parser failed.
|
||||
ExceptionOr<location::nearby::connections::OfflineFrame> FromBytes(
|
||||
const ByteArray& offline_frame_bytes);
|
||||
absl::string_view offline_frame_bytes);
|
||||
|
||||
// Returns FrameType of a parsed message, or
|
||||
// V1Frame::UNKNOWN_FRAME_TYPE, if frame contents is not recognized.
|
||||
@@ -51,49 +51,49 @@ location::nearby::connections::V1Frame::FrameType GetFrameType(
|
||||
const location::nearby::connections::OfflineFrame& offline_frame);
|
||||
|
||||
// Builds Connection Request / Response messages.
|
||||
ByteArray ForConnectionRequestConnections(
|
||||
std::string ForConnectionRequestConnections(
|
||||
const location::nearby::connections::ConnectionsDevice&
|
||||
proto_connections_device,
|
||||
const ConnectionInfo& connection_info);
|
||||
ByteArray ForConnectionRequestPresence(
|
||||
std::string ForConnectionRequestPresence(
|
||||
const location::nearby::connections::PresenceDevice& proto_presence_device,
|
||||
const ConnectionInfo& connection_info);
|
||||
ByteArray ForConnectionResponse(
|
||||
std::string ForConnectionResponse(
|
||||
std::int32_t status, const location::nearby::connections::OsInfo& os_info,
|
||||
std::int32_t multiplex_socket_bitmask);
|
||||
|
||||
// Builds Payload transfer messages.
|
||||
ByteArray ForDataPayloadTransfer(
|
||||
std::string ForDataPayloadTransfer(
|
||||
const location::nearby::connections::PayloadTransferFrame::PayloadHeader&
|
||||
header,
|
||||
const location::nearby::connections::PayloadTransferFrame::PayloadChunk&
|
||||
chunk);
|
||||
ByteArray ForControlPayloadTransfer(
|
||||
std::string ForControlPayloadTransfer(
|
||||
const location::nearby::connections::PayloadTransferFrame::PayloadHeader&
|
||||
header,
|
||||
const location::nearby::connections::PayloadTransferFrame::ControlMessage&
|
||||
control);
|
||||
ByteArray ForPayloadAckPayloadTransfer(std::int64_t payload_id);
|
||||
std::string ForPayloadAckPayloadTransfer(std::int64_t payload_id);
|
||||
|
||||
// Builds Bandwidth Upgrade [BWU] messages.
|
||||
ByteArray ForBwuIntroduction(const std::string& endpoint_id,
|
||||
std::string ForBwuIntroduction(const std::string& endpoint_id,
|
||||
bool supports_disabling_encryption);
|
||||
ByteArray ForBwuIntroductionAck();
|
||||
ByteArray ForBwuWifiHotspotPathAvailable(
|
||||
std::string ForBwuIntroductionAck();
|
||||
std::string ForBwuWifiHotspotPathAvailable(
|
||||
location::nearby::connections::BandwidthUpgradeNegotiationFrame::
|
||||
UpgradePathInfo::WifiHotspotCredentials credentials,
|
||||
bool supports_disabling_encryption);
|
||||
ByteArray ForBwuWifiLanPathAvailable(
|
||||
std::string ForBwuWifiLanPathAvailable(
|
||||
const std::vector<ServiceAddress>& addresses);
|
||||
ByteArray ForBwuAwdlPathAvailable(const std::string& service_name,
|
||||
std::string ForBwuAwdlPathAvailable(const std::string& service_name,
|
||||
const std::string& service_type,
|
||||
const std::string& password,
|
||||
bool supports_disabling_encryption);
|
||||
ByteArray ForBwuWifiAwarePathAvailable(const std::string& service_id,
|
||||
std::string ForBwuWifiAwarePathAvailable(const std::string& service_id,
|
||||
const std::string& service_info,
|
||||
const std::string& password,
|
||||
bool supports_disabling_encryption);
|
||||
ByteArray ForBwuWifiDirectPathAvailable(const std::string& ssid,
|
||||
std::string ForBwuWifiDirectPathAvailable(const std::string& ssid,
|
||||
const std::string& password,
|
||||
std::int32_t port,
|
||||
std::int32_t frequency,
|
||||
@@ -101,21 +101,21 @@ ByteArray ForBwuWifiDirectPathAvailable(const std::string& ssid,
|
||||
const std::string& gateway,
|
||||
const std::string& service_name,
|
||||
const std::string& pin);
|
||||
ByteArray ForBwuBluetoothPathAvailable(const std::string& service_id,
|
||||
std::string ForBwuBluetoothPathAvailable(const std::string& service_id,
|
||||
MacAddress mac_address);
|
||||
ByteArray ForBwuWebrtcPathAvailable(
|
||||
std::string ForBwuWebrtcPathAvailable(
|
||||
const std::string& peer_id,
|
||||
const location::nearby::connections::LocationHint& location_hint_a);
|
||||
ByteArray ForBwuFailure(const UpgradePathInfo& info);
|
||||
ByteArray ForBwuPathRequest(
|
||||
std::string ForBwuFailure(const UpgradePathInfo& info);
|
||||
std::string ForBwuPathRequest(
|
||||
const std::vector<Medium>& mediums,
|
||||
const location::nearby::connections::MediumRole& medium_role);
|
||||
ByteArray ForBwuLastWrite();
|
||||
ByteArray ForBwuSafeToClose();
|
||||
std::string ForBwuLastWrite();
|
||||
std::string ForBwuSafeToClose();
|
||||
|
||||
ByteArray ForKeepAlive();
|
||||
ByteArray ForKeepAlive(bool ack, uint32_t seq_num);
|
||||
ByteArray ForDisconnection(bool request_safe_to_disconnect,
|
||||
std::string ForKeepAlive();
|
||||
std::string ForKeepAlive(bool ack, uint32_t seq_num);
|
||||
std::string ForDisconnection(bool request_safe_to_disconnect,
|
||||
bool ack_safe_to_disconnect);
|
||||
UpgradePathInfo::Medium MediumToUpgradePathInfoMedium(Medium medium);
|
||||
Medium UpgradePathInfoMediumToMedium(UpgradePathInfo::Medium medium);
|
||||
|
||||
@@ -88,8 +88,7 @@ TEST(OfflineFramesTest, CanParseMessageFromBytes) {
|
||||
sub_frame->add_mediums(MediumToConnectionRequestMedium(medium));
|
||||
}
|
||||
}
|
||||
auto serialized_bytes = ByteArray(tx_message.SerializeAsString());
|
||||
auto ret_value = FromBytes(serialized_bytes);
|
||||
auto ret_value = FromBytes(tx_message.SerializeAsString());
|
||||
ASSERT_TRUE(ret_value.ok());
|
||||
const auto& rx_message = ret_value.result();
|
||||
EXPECT_THAT(rx_message, EqualsProto(tx_message));
|
||||
@@ -141,8 +140,8 @@ TEST(OfflineFramesTest, CanGenerateLegacyConnectionRequest) {
|
||||
kMediums.begin(), kMediums.end()),
|
||||
kKeepAliveIntervalMillis,
|
||||
kKeepAliveTimeoutMillis};
|
||||
ByteArray bytes = ForConnectionRequestConnections({}, connection_info);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response =
|
||||
FromBytes(ForConnectionRequestConnections({}, connection_info));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -208,9 +207,8 @@ TEST(OfflineFramesTest, CanGenerateConnectionsConnectionRequest) {
|
||||
kKeepAliveIntervalMillis,
|
||||
kKeepAliveTimeoutMillis,
|
||||
medium_role};
|
||||
ByteArray bytes =
|
||||
ForConnectionRequestConnections(connections_device, connection_info);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response = FromBytes(
|
||||
ForConnectionRequestConnections(connections_device, connection_info));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -268,9 +266,8 @@ TEST(OfflineFramesTest, CanGeneratePresenceConnectionRequest) {
|
||||
presence_device.set_endpoint_type(
|
||||
location::nearby::connections::PRESENCE_ENDPOINT);
|
||||
presence_device.set_device_name("TEST DEVICE");
|
||||
ByteArray bytes =
|
||||
ForConnectionRequestPresence(presence_device, connection_info);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response =
|
||||
FromBytes(ForConnectionRequestPresence(presence_device, connection_info));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -336,9 +333,8 @@ TEST(OfflineFramesTest,
|
||||
location::nearby::connections::CONNECTIONS_ENDPOINT);
|
||||
connections_device.set_endpoint_info("XYZ");
|
||||
|
||||
ByteArray bytes =
|
||||
ForConnectionRequestConnections(connections_device, connection_info);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response = FromBytes(
|
||||
ForConnectionRequestConnections(connections_device, connection_info));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -365,9 +361,8 @@ TEST(OfflineFramesTest, CanGenerateConnectionResponse) {
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kSafeToDisconnectVersion,
|
||||
5);
|
||||
ByteArray bytes =
|
||||
ForConnectionResponse(1, os_info, /*multiplex_socket_bitmask=*/0x01);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response = FromBytes(
|
||||
ForConnectionResponse(1, os_info, /*multiplex_socket_bitmask=*/0x01));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -393,8 +388,7 @@ TEST(OfflineFramesTest, CanGenerateControlPayloadTransfer) {
|
||||
control_message: < event: PAYLOAD_CANCELED offset: 150 >
|
||||
>
|
||||
>)pb";
|
||||
ByteArray bytes = ForControlPayloadTransfer(header, control);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response = FromBytes(ForControlPayloadTransfer(header, control));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -421,8 +415,7 @@ TEST(OfflineFramesTest, CanGenerateDataPayloadTransfer) {
|
||||
payload_chunk: < flags: 1 offset: 150 body: "payload data" >
|
||||
>
|
||||
>)pb";
|
||||
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response = FromBytes(ForDataPayloadTransfer(header, chunk));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -439,8 +432,7 @@ TEST(OfflineFramesTest, CanGeneratePayloadAckPayloadTransfer) {
|
||||
payload_header: < id: 12345 total_size: -1 >
|
||||
>
|
||||
>)pb";
|
||||
ByteArray bytes = ForPayloadAckPayloadTransfer(12345);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response = FromBytes(ForPayloadAckPayloadTransfer(12345));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -487,9 +479,8 @@ TEST(OfflineFramesTest, CanGenerateBwuWifiHotspotPathAvailable) {
|
||||
address_candidate = credentials.add_address_candidates();
|
||||
address_candidate->set_ip_address(std::string("\xc0\xa8\x00\x01", 4));
|
||||
address_candidate->set_port(5678);
|
||||
ByteArray bytes =
|
||||
ForBwuWifiHotspotPathAvailable(std::move(credentials), false);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response =
|
||||
FromBytes(ForBwuWifiHotspotPathAvailable(std::move(credentials), false));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -521,7 +512,7 @@ TEST(OfflineFramesTest, CanGenerateBwuWifiLanPathAvailable) {
|
||||
>
|
||||
>
|
||||
>)pb";
|
||||
ByteArray bytes = ForBwuWifiLanPathAvailable(
|
||||
std::string bytes = ForBwuWifiLanPathAvailable(
|
||||
{ServiceAddress{
|
||||
.address = {'\x2a', '\x00', '\x79', '\xe0', '\x2e', '\x87', '\x00',
|
||||
'\x06', '\xb7', '\x28', '\x67', '\x45', '\x7a', '\xdd',
|
||||
@@ -555,9 +546,8 @@ TEST(OfflineFramesTest, CanGenerateBwuAwdlPathAvailable) {
|
||||
>
|
||||
>
|
||||
>)pb";
|
||||
ByteArray bytes = ForBwuAwdlPathAvailable("service_name", "nearby_upgrade",
|
||||
"password", true);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response = FromBytes(ForBwuAwdlPathAvailable(
|
||||
"service_name", "nearby_upgrade", "password", true));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -583,9 +573,9 @@ TEST(OfflineFramesTest, CanGenerateBwuWifiAwarePathAvailable) {
|
||||
>
|
||||
>
|
||||
>)pb";
|
||||
ByteArray bytes = ForBwuWifiAwarePathAvailable("service_id", "service_info",
|
||||
"password", false);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response = FromBytes(
|
||||
ForBwuWifiAwarePathAvailable("service_id", "service_info", "password",
|
||||
/*supports_disabling_encryption=*/false));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -615,10 +605,10 @@ TEST(OfflineFramesTest, CanGenerateBwuWifiDirectPathAvailable) {
|
||||
>
|
||||
>
|
||||
>)pb";
|
||||
ByteArray bytes = ForBwuWifiDirectPathAvailable(
|
||||
"", "", 1000, 2412, false, "192.168.1.1",
|
||||
"NC-WifiDirectTest", "b592f7d3");
|
||||
auto response = FromBytes(bytes);
|
||||
auto response = FromBytes(ForBwuWifiDirectPathAvailable(
|
||||
/*ssid=*/"", /*password=*/"", /*port=*/1000, /*frequency=*/2412,
|
||||
/*supports_disabling_encryption=*/false, "192.168.1.1",
|
||||
"NC-WifiDirectTest", "b592f7d3"));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -644,8 +634,8 @@ TEST(OfflineFramesTest, CanGenerateBwuBluetoothPathAvailable) {
|
||||
>)pb";
|
||||
MacAddress mac_address;
|
||||
MacAddress::FromString("11:22:33:44:55:66", mac_address);
|
||||
ByteArray bytes = ForBwuBluetoothPathAvailable("service", mac_address);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response =
|
||||
FromBytes(ForBwuBluetoothPathAvailable("service", mac_address));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -659,8 +649,7 @@ TEST(OfflineFramesTest, CanGenerateBwuLastWrite) {
|
||||
type: BANDWIDTH_UPGRADE_NEGOTIATION
|
||||
bandwidth_upgrade_negotiation: < event_type: LAST_WRITE_TO_PRIOR_CHANNEL >
|
||||
>)pb";
|
||||
ByteArray bytes = ForBwuLastWrite();
|
||||
auto response = FromBytes(bytes);
|
||||
auto response = FromBytes(ForBwuLastWrite());
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -674,8 +663,7 @@ TEST(OfflineFramesTest, CanGenerateBwuSafeToClose) {
|
||||
type: BANDWIDTH_UPGRADE_NEGOTIATION
|
||||
bandwidth_upgrade_negotiation: < event_type: SAFE_TO_CLOSE_PRIOR_CHANNEL >
|
||||
>)pb";
|
||||
ByteArray bytes = ForBwuSafeToClose();
|
||||
auto response = FromBytes(bytes);
|
||||
auto response = FromBytes(ForBwuSafeToClose());
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -695,9 +683,8 @@ TEST(OfflineFramesTest, CanGenerateBwuIntroduction) {
|
||||
>
|
||||
>
|
||||
>)pb";
|
||||
ByteArray bytes = ForBwuIntroduction(
|
||||
std::string(kEndpointId), false /* supports_disabling_encryption */);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response = FromBytes(ForBwuIntroduction(
|
||||
std::string(kEndpointId), false /* supports_disabling_encryption */));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -711,8 +698,7 @@ TEST(OfflineFramesTest, CanGenerateKeepAlive) {
|
||||
type: KEEP_ALIVE
|
||||
keep_alive: <>
|
||||
>)pb";
|
||||
ByteArray bytes = ForKeepAlive();
|
||||
auto response = FromBytes(bytes);
|
||||
auto response = FromBytes(ForKeepAlive());
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -729,9 +715,9 @@ TEST(OfflineFramesTest, CanGenerateDisconnection) {
|
||||
ack_safe_to_disconnect: true
|
||||
>
|
||||
>)pb";
|
||||
ByteArray bytes = ForDisconnection(/* request_safe_to_disconnect */ true,
|
||||
/* ack_safe_to_disconnect */ true);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response =
|
||||
FromBytes(ForDisconnection(/* request_safe_to_disconnect */ true,
|
||||
/* ack_safe_to_disconnect */ true));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
@@ -760,8 +746,7 @@ TEST(OfflineFramesTest, CanGenerateBwuPathRequest) {
|
||||
mediums.push_back(Medium::WIFI_HOTSPOT);
|
||||
MediumRole medium_role;
|
||||
medium_role.set_support_wifi_hotspot_client(true);
|
||||
ByteArray bytes = ForBwuPathRequest(mediums, medium_role);
|
||||
auto response = FromBytes(bytes);
|
||||
auto response = FromBytes(ForBwuPathRequest(mediums, medium_role));
|
||||
ASSERT_TRUE(response.ok());
|
||||
OfflineFrame message = response.result();
|
||||
EXPECT_THAT(message, EqualsProto(kExpected));
|
||||
|
||||
@@ -66,24 +66,24 @@ constexpr int kKeepAliveTimeoutMillis = 5000;
|
||||
|
||||
class OfflineFramesConnectionRequestTest : public testing::Test {
|
||||
protected:
|
||||
ConnectionInfo connection_info_{std::string(kEndpointId),
|
||||
ByteArray{std::string(kEndpointName)},
|
||||
kNonce,
|
||||
kSupports5ghz,
|
||||
std::string(kBssid),
|
||||
kApFrequency,
|
||||
std::vector<Medium, std::allocator<Medium>>(
|
||||
kMediums.begin(), kMediums.end()),
|
||||
kKeepAliveIntervalMillis,
|
||||
kKeepAliveTimeoutMillis};
|
||||
ConnectionInfo connection_info_{
|
||||
std::string(kEndpointId),
|
||||
ByteArray{std::string(kEndpointName)},
|
||||
kNonce,
|
||||
kSupports5ghz,
|
||||
std::string(kBssid),
|
||||
kApFrequency,
|
||||
std::vector<Medium>(kMediums.begin(), kMediums.end()),
|
||||
kKeepAliveIntervalMillis,
|
||||
kKeepAliveTimeoutMillis};
|
||||
};
|
||||
|
||||
TEST_F(OfflineFramesConnectionRequestTest,
|
||||
ValidatesAsOkWithValidConnectionRequestFrame) {
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForConnectionRequestConnections({}, connection_info_);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForConnectionRequestConnections({}, connection_info_);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -94,8 +94,8 @@ TEST_F(OfflineFramesConnectionRequestTest,
|
||||
ValidatesAsFailWithNullConnectionRequestFrame) {
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForConnectionRequestConnections({}, connection_info_);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForConnectionRequestConnections({}, connection_info_);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
auto* v1_frame = offline_frame.mutable_v1();
|
||||
|
||||
v1_frame->clear_connection_request();
|
||||
@@ -110,8 +110,8 @@ TEST_F(OfflineFramesConnectionRequestTest,
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
connection_info_.local_endpoint_id = "";
|
||||
ByteArray bytes = ForConnectionRequestConnections({}, connection_info_);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForConnectionRequestConnections({}, connection_info_);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -121,9 +121,9 @@ TEST_F(OfflineFramesConnectionRequestTest,
|
||||
TEST_F(OfflineFramesConnectionRequestTest,
|
||||
ValidatesAsFailWithEmptyEndpointIdInConnectionRequestFrame) {
|
||||
connection_info_.local_endpoint_id = "";
|
||||
ByteArray bytes = ForConnectionRequestConnections({}, connection_info_);
|
||||
std::string bytes = ForConnectionRequestConnections({}, connection_info_);
|
||||
location::nearby::connections::OfflineFrame frame;
|
||||
frame.ParseFromString(bytes.AsStringView());
|
||||
frame.ParseFromString(bytes);
|
||||
frame.mutable_v1()->mutable_connection_request()->set_endpoint_id("");
|
||||
ASSERT_TRUE(frame.v1().connection_request().has_endpoint_id());
|
||||
|
||||
@@ -140,8 +140,8 @@ TEST_F(OfflineFramesConnectionRequestTest,
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
connection_info_.local_endpoint_info = ByteArray{""};
|
||||
ByteArray bytes = ForConnectionRequestConnections({}, connection_info_);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForConnectionRequestConnections({}, connection_info_);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -153,8 +153,8 @@ TEST_F(OfflineFramesConnectionRequestTest,
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
connection_info_.bssid = "";
|
||||
ByteArray bytes = ForConnectionRequestConnections({}, connection_info_);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForConnectionRequestConnections({}, connection_info_);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -166,8 +166,8 @@ TEST_F(OfflineFramesConnectionRequestTest,
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
connection_info_.supported_mediums = {};
|
||||
ByteArray bytes = ForConnectionRequestConnections({}, connection_info_);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForConnectionRequestConnections({}, connection_info_);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -179,9 +179,9 @@ TEST(OfflineFramesValidatorTest,
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
OsInfo os_info;
|
||||
ByteArray bytes = ForConnectionResponse(kStatusAccepted, os_info,
|
||||
std::string bytes = ForConnectionResponse(kStatusAccepted, os_info,
|
||||
/*multiplex_socket_bitmask=*/0);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -193,9 +193,9 @@ TEST(OfflineFramesValidatorTest,
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
OsInfo os_info;
|
||||
ByteArray bytes = ForConnectionResponse(kStatusAccepted, os_info,
|
||||
std::string bytes = ForConnectionResponse(kStatusAccepted, os_info,
|
||||
/*multiplex_socket_bitmask=*/0);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
offline_frame.ParseFromString(bytes);
|
||||
auto* v1_frame = offline_frame.mutable_v1();
|
||||
|
||||
v1_frame->clear_connection_response();
|
||||
@@ -210,9 +210,9 @@ TEST(OfflineFramesValidatorTest,
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
OsInfo os_info;
|
||||
ByteArray bytes =
|
||||
std::string bytes =
|
||||
ForConnectionResponse(-1, os_info, /*multiplex_socket_bitmask=*/0);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -234,8 +234,8 @@ TEST(OfflineFramesValidatorTest, ValidatesAsOkWithValidPayloadTransferFrame) {
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -259,8 +259,8 @@ TEST(OfflineFramesValidatorTest,
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -284,8 +284,8 @@ TEST(OfflineFramesValidatorTest, ValidatesAsOkTypeFileWithLegalFilePath) {
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -309,8 +309,8 @@ TEST(OfflineFramesValidatorTest, ValidatesAsFailedTypeFileWithIllegalFilePath) {
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -334,8 +334,8 @@ TEST(OfflineFramesValidatorTest, ValidatesAsOkTypeFileWithLegalParentFolder) {
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -360,8 +360,8 @@ TEST(OfflineFramesValidatorTest,
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -377,8 +377,8 @@ TEST(OfflineFramesValidatorTest, ValidatesAsFailWithNullPayloadTransferFrame) {
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
auto* v1_frame = offline_frame.mutable_v1();
|
||||
|
||||
v1_frame->clear_payload_transfer();
|
||||
@@ -401,8 +401,8 @@ TEST(OfflineFramesValidatorTest,
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
auto* v1_frame = offline_frame.mutable_v1();
|
||||
auto* payload_transfer = v1_frame->mutable_payload_transfer();
|
||||
|
||||
@@ -426,8 +426,8 @@ TEST(OfflineFramesValidatorTest,
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -447,8 +447,8 @@ TEST(OfflineFramesValidatorTest,
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
auto* v1_frame = offline_frame.mutable_v1();
|
||||
auto* payload_transfer = v1_frame->mutable_payload_transfer();
|
||||
|
||||
@@ -472,8 +472,8 @@ TEST(OfflineFramesValidatorTest,
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -493,8 +493,8 @@ TEST(OfflineFramesValidatorTest,
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -514,8 +514,8 @@ TEST(OfflineFramesValidatorTest,
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
auto* v1_frame = offline_frame.mutable_v1();
|
||||
auto* payload_transfer = v1_frame->mutable_payload_transfer();
|
||||
auto* payload_chunk = payload_transfer->mutable_payload_chunk();
|
||||
@@ -539,8 +539,8 @@ TEST(OfflineFramesValidatorTest,
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForControlPayloadTransfer(header, control);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForControlPayloadTransfer(header, control);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto* v1_frame = offline_frame.mutable_v1();
|
||||
auto* payload_transfer = v1_frame->mutable_payload_transfer();
|
||||
@@ -564,8 +564,8 @@ TEST(OfflineFramesValidatorTest,
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForControlPayloadTransfer(header, control);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForControlPayloadTransfer(header, control);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -584,8 +584,8 @@ TEST(OfflineFramesValidatorTest,
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForControlPayloadTransfer(header, control);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForControlPayloadTransfer(header, control);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -603,9 +603,9 @@ TEST(OfflineFramesValidatorTest,
|
||||
credentials.set_port(kPort);
|
||||
credentials.set_frequency(kHotspotFrequency);
|
||||
credentials.set_gateway(kWifiHotspotGateway);
|
||||
ByteArray bytes = ForBwuWifiHotspotPathAvailable(
|
||||
std::string bytes = ForBwuWifiHotspotPathAvailable(
|
||||
std::move(credentials), kSupportsDisablingEncryption);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -628,9 +628,9 @@ TEST(OfflineFramesValidatorTest,
|
||||
candidate = credentials.mutable_address_candidates()->Add();
|
||||
candidate->set_ip_address(std::string("\xc0\xa8\x00\x01", 4));
|
||||
candidate->set_port(kPort);
|
||||
ByteArray bytes = ForBwuWifiHotspotPathAvailable(
|
||||
std::string bytes = ForBwuWifiHotspotPathAvailable(
|
||||
std::move(credentials), kSupportsDisablingEncryption);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -650,9 +650,9 @@ TEST(OfflineFramesValidatorTest,
|
||||
candidate->set_ip_address(std::string(
|
||||
"\xfe\x80\x00\x00\x00\x00\x00\x00\x4d\xb2\xb3\x5c\x22\x03\x98\xa1", 12));
|
||||
candidate->set_port(kPort);
|
||||
ByteArray bytes = ForBwuWifiHotspotPathAvailable(
|
||||
std::string bytes = ForBwuWifiHotspotPathAvailable(
|
||||
std::move(credentials), kSupportsDisablingEncryption);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -671,9 +671,9 @@ TEST(OfflineFramesValidatorTest,
|
||||
auto* candidate = credentials.mutable_address_candidates()->Add();
|
||||
candidate->set_ip_address(std::string(
|
||||
"\xfe\x80\x00\x00\x00\x00\x00\x00\x4d\xb2\xb3\x5c\x22\x03\x98\xa1", 16));
|
||||
ByteArray bytes = ForBwuWifiHotspotPathAvailable(
|
||||
std::string bytes = ForBwuWifiHotspotPathAvailable(
|
||||
std::move(credentials), kSupportsDisablingEncryption);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -689,8 +689,8 @@ TEST(OfflineFramesValidatorTest,
|
||||
kPort},
|
||||
{{'\xc0', '\xa8', '\x00', '\x01'}, kPort},
|
||||
};
|
||||
ByteArray bytes = ForBwuWifiLanPathAvailable(address_candidates);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = ForBwuWifiLanPathAvailable(address_candidates);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -708,9 +708,9 @@ TEST(OfflineFramesValidatorTest,
|
||||
credentials.set_port(kPort);
|
||||
credentials.set_frequency(kHotspotFrequency);
|
||||
credentials.set_gateway(kWifiHotspotGateway);
|
||||
ByteArray bytes = ForBwuWifiHotspotPathAvailable(
|
||||
std::string bytes = ForBwuWifiHotspotPathAvailable(
|
||||
std::move(credentials), kSupportsDisablingEncryption);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
offline_frame.ParseFromString(bytes);
|
||||
auto* v1_frame = offline_frame.mutable_v1();
|
||||
|
||||
v1_frame->clear_bandwidth_upgrade_negotiation();
|
||||
@@ -723,11 +723,11 @@ TEST(OfflineFramesValidatorTest,
|
||||
TEST(OfflineFramesValidatorTest, ValidatesAsOkBandwidthUpgradeWifiDirect) {
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = ForBwuWifiDirectPathAvailable(
|
||||
std::string bytes = ForBwuWifiDirectPathAvailable(
|
||||
std::string(kWifiDirectSsid), std::string(kWifiDirectPassword), kPort,
|
||||
kWifiDirectFrequency, kSupportsDisablingEncryption, std::string(kGateway),
|
||||
std::string(kWifiDirectServiceName), std::string(kWifiDirectPin));
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame);
|
||||
|
||||
@@ -740,11 +740,11 @@ TEST(OfflineFramesValidatorTest,
|
||||
OfflineFrame offline_frame_2;
|
||||
|
||||
// Anything less than -1 is invalid
|
||||
ByteArray bytes = ForBwuWifiDirectPathAvailable(
|
||||
std::string bytes = ForBwuWifiDirectPathAvailable(
|
||||
std::string(kWifiDirectSsid), std::string(kWifiDirectPassword), kPort, -2,
|
||||
kSupportsDisablingEncryption, std::string(kGateway),
|
||||
std::string(kWifiDirectServiceName), std::string(kWifiDirectPin));
|
||||
offline_frame_1.ParseFromString(std::string(bytes));
|
||||
offline_frame_1.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame_1);
|
||||
|
||||
@@ -755,7 +755,7 @@ TEST(OfflineFramesValidatorTest,
|
||||
std::string(kWifiDirectSsid), std::string(kWifiDirectPassword), kPort, -1,
|
||||
kSupportsDisablingEncryption, std::string(kGateway),
|
||||
std::string(kWifiDirectServiceName), std::string(kWifiDirectPin));
|
||||
offline_frame_2.ParseFromString(std::string(bytes));
|
||||
offline_frame_2.ParseFromString(bytes);
|
||||
|
||||
ret_value = EnsureValidOfflineFrame(offline_frame_2);
|
||||
|
||||
@@ -769,12 +769,12 @@ TEST(OfflineFramesValidatorTest,
|
||||
|
||||
std::string wifi_direct_ssid{"DIRECT-A*-0123456789AB"};
|
||||
std::string wifi_direct_pin_wrong_length = "abc";
|
||||
ByteArray bytes = ForBwuWifiDirectPathAvailable(
|
||||
std::string bytes = ForBwuWifiDirectPathAvailable(
|
||||
wifi_direct_ssid, std::string(kWifiDirectPassword), kPort,
|
||||
kWifiDirectFrequency, kSupportsDisablingEncryption,
|
||||
std::string(kGateway), std::string(kWifiDirectServiceName),
|
||||
wifi_direct_pin_wrong_length);
|
||||
offline_frame_1.ParseFromString(std::string(bytes));
|
||||
offline_frame_1.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame_1);
|
||||
|
||||
@@ -790,7 +790,7 @@ TEST(OfflineFramesValidatorTest,
|
||||
kWifiDirectFrequency, kSupportsDisablingEncryption,
|
||||
std::string(kGateway), wifi_direct_service_name_wrong_length,
|
||||
std::string(kWifiDirectPin));
|
||||
offline_frame_2.ParseFromString(std::string(bytes));
|
||||
offline_frame_2.ParseFromString(bytes);
|
||||
|
||||
ret_value = EnsureValidOfflineFrame(offline_frame_2);
|
||||
|
||||
@@ -804,12 +804,12 @@ TEST(OfflineFramesValidatorTest,
|
||||
|
||||
std::string short_wifi_direct_password{"Test"};
|
||||
std::string short_wifi_direct_pin{"abc"};
|
||||
ByteArray bytes = ForBwuWifiDirectPathAvailable(
|
||||
std::string bytes = ForBwuWifiDirectPathAvailable(
|
||||
std::string(kWifiDirectSsid), short_wifi_direct_password, kPort,
|
||||
kWifiDirectFrequency, kSupportsDisablingEncryption,
|
||||
std::string(kGateway), std::string(kWifiDirectServiceName),
|
||||
short_wifi_direct_pin);
|
||||
offline_frame_1.ParseFromString(std::string(bytes));
|
||||
offline_frame_1.ParseFromString(bytes);
|
||||
|
||||
auto ret_value = EnsureValidOfflineFrame(offline_frame_1);
|
||||
|
||||
@@ -826,7 +826,7 @@ TEST(OfflineFramesValidatorTest,
|
||||
kWifiDirectFrequency, kSupportsDisablingEncryption,
|
||||
std::string(kGateway), std::string(kWifiDirectServiceName),
|
||||
long_wifi_direct_pin);
|
||||
offline_frame_2.ParseFromString(std::string(bytes));
|
||||
offline_frame_2.ParseFromString(bytes);
|
||||
|
||||
ret_value = EnsureValidOfflineFrame(offline_frame_2);
|
||||
|
||||
|
||||
@@ -113,8 +113,8 @@ class PayloadSimulationUser : public SimulationUser {
|
||||
|
||||
OfflineFrame offline_frame;
|
||||
|
||||
ByteArray bytes = parser::ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(std::string(bytes));
|
||||
std::string bytes = parser::ForDataPayloadTransfer(header, chunk);
|
||||
offline_frame.ParseFromString(bytes);
|
||||
|
||||
PacketMetaData packet_meta_data;
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "connections/implementation/proto/offline_wire_formats.pb.h"
|
||||
#include "connections/implementation/webrtc_endpoint_channel.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
@@ -132,7 +131,7 @@ void WebrtcBwuHandler::HandleRevertInitiatorStateForService(
|
||||
// Called by BWU initiator. Set up WebRTC upgraded medium for this endpoint,
|
||||
// and returns a upgrade path info (PeerId, LocationHint) for remote party to
|
||||
// perform discovery.
|
||||
ByteArray WebrtcBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string WebrtcBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) {
|
||||
LocationHint location_hint =
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "connections/implementation/mediums/webrtc.h"
|
||||
#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 {
|
||||
@@ -69,7 +68,7 @@ class WebrtcBwuHandler : public BaseBwuHandler {
|
||||
const std::string& endpoint_id) final {}
|
||||
|
||||
// BaseBwuHandler implementation:
|
||||
ByteArray HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) final;
|
||||
void HandleRevertInitiatorStateForService(
|
||||
|
||||
@@ -65,7 +65,7 @@ void WebrtcBwuHandler::HandleRevertInitiatorStateForService(
|
||||
// Called by BWU initiator. Set up WebRTC upgraded medium for this endpoint,
|
||||
// and returns a upgrade path info (PeerId, LocationHint) for remote party to
|
||||
// perform discovery.
|
||||
ByteArray WebrtcBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string WebrtcBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) {
|
||||
return {};
|
||||
|
||||
@@ -68,7 +68,7 @@ class WebrtcBwuHandler : public BaseBwuHandler {
|
||||
const std::string& endpoint_id) final {}
|
||||
|
||||
// BaseBwuHandler implementation:
|
||||
ByteArray HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) final;
|
||||
void HandleRevertInitiatorStateForService(
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "connections/implementation/wifi_direct_endpoint_channel.h"
|
||||
#include "connections/strategy.h"
|
||||
#include "internal/base/masker.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/wifi_credential.h"
|
||||
@@ -49,7 +48,7 @@ WifiDirectBwuHandler::WifiDirectBwuHandler(
|
||||
// Called by BWU initiator. Set up WifiDirect upgraded medium for this
|
||||
// endpoint, and returns an upgrade path info (ServiceName, Pin for Wifi WPS,
|
||||
// Gateway used as IPAddress, Port) for remote party to perform connection.
|
||||
ByteArray WifiDirectBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string WifiDirectBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) {
|
||||
// Create WifiDirect GO
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "connections/implementation/endpoint_channel.h"
|
||||
#include "connections/implementation/mediums/mediums.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"
|
||||
|
||||
@@ -73,7 +72,7 @@ class WifiDirectBwuHandler : public BaseBwuHandler {
|
||||
// Called by BWU initiator. Set up WifiDirect upgraded medium for this
|
||||
// endpoint, and returns a upgrade path info (SSID, Password, Gateway used as
|
||||
// IPAddress, Port) for remote party to perform connection.
|
||||
ByteArray HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) final;
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "connections/implementation/wifi_direct_bwu_handler.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/expected.h"
|
||||
@@ -98,10 +97,10 @@ TEST_F(WifiDirectTest, WFDGOBWUInit_GCCreateEndpointChannel) {
|
||||
|
||||
SingleThreadExecutor wfd_go_executor;
|
||||
wfd_go_executor.Execute([&]() {
|
||||
ByteArray upgrade_path_available_frame =
|
||||
std::string upgrade_path_available_frame =
|
||||
wfd_go_bwu_handler->InitializeUpgradedMediumForEndpoint(
|
||||
&wifi_direct_go, std::string(kServiceID), std::string(kEndpointID));
|
||||
EXPECT_FALSE(upgrade_path_available_frame.Empty());
|
||||
EXPECT_FALSE(upgrade_path_available_frame.empty());
|
||||
|
||||
upgrade_frame = parser::FromBytes(upgrade_path_available_frame);
|
||||
start_latch.CountDown();
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
#include "connections/implementation/wifi_hotspot_endpoint_channel.h"
|
||||
#include "connections/strategy.h"
|
||||
#include "internal/base/masker.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/expected.h"
|
||||
#include "internal/platform/implementation/wifi_utils.h"
|
||||
#include "internal/platform/logging.h"
|
||||
@@ -74,7 +73,7 @@ WifiHotspotBwuHandler::WifiHotspotBwuHandler(
|
||||
// Called by BWU initiator. Set up WifiHotspot upgraded medium for this
|
||||
// endpoint, and returns a upgrade path info (SSID, Password, Gateway used as
|
||||
// IPAddress, Port) for remote party to perform connection.
|
||||
ByteArray WifiHotspotBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string WifiHotspotBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) {
|
||||
// Create SoftAP
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#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"
|
||||
|
||||
@@ -68,7 +67,7 @@ class WifiHotspotBwuHandler : public BaseBwuHandler {
|
||||
};
|
||||
|
||||
// BaseBwuHandler implementation:
|
||||
ByteArray HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) final;
|
||||
void HandleRevertInitiatorStateForService(
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "connections/implementation/offline_frames.h"
|
||||
#include "connections/implementation/wifi_hotspot_bwu_handler.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/expected.h"
|
||||
@@ -100,11 +99,11 @@ TEST_F(WifiHotspotTest, SoftAPBWUInit_STACreateEndpointChannel) {
|
||||
// client_hotspot_ap works as Hotspot SoftAP
|
||||
SingleThreadExecutor server_executor;
|
||||
server_executor.Execute([&]() {
|
||||
ByteArray upgrade_path_available_frame =
|
||||
std::string upgrade_path_available_frame =
|
||||
handler_1->InitializeUpgradedMediumForEndpoint(
|
||||
&client_hotspot_ap, std::string(kServiceID),
|
||||
std::string(kEndpointID));
|
||||
EXPECT_FALSE(upgrade_path_available_frame.Empty());
|
||||
EXPECT_FALSE(upgrade_path_available_frame.empty());
|
||||
|
||||
upgrade_frame = parser::FromBytes(upgrade_path_available_frame);
|
||||
start_latch.CountDown();
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#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/upgrade_address_info.h"
|
||||
#include "internal/platform/logging.h"
|
||||
@@ -118,7 +117,7 @@ WifiLanBwuHandler::CreateUpgradedEndpointChannel(
|
||||
// Called by BWU initiator. Set up WifiLan upgraded medium for this endpoint,
|
||||
// and returns a upgrade path info (ip address, port) for remote party to
|
||||
// perform discovery.
|
||||
ByteArray WifiLanBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string WifiLanBwuHandler::HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) {
|
||||
if (!wifi_lan_medium_.IsAcceptingConnections(upgrade_service_id)) {
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#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"
|
||||
|
||||
@@ -68,7 +67,7 @@ class WifiLanBwuHandler : public BaseBwuHandler {
|
||||
};
|
||||
|
||||
// BaseBwuHandler implementation:
|
||||
ByteArray HandleInitializeUpgradedMediumForEndpoint(
|
||||
std::string HandleInitializeUpgradedMediumForEndpoint(
|
||||
ClientProxy* client, const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) final;
|
||||
void HandleRevertInitiatorStateForService(
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "connections/strategy.h"
|
||||
#include "internal/analytics/mock_event_logger.h"
|
||||
#include "internal/analytics/sharing_log_matchers.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/implementation/platform.h"
|
||||
#include "internal/platform/implementation/upgrade_address_info.h"
|
||||
#include "internal/platform/implementation/wifi_lan.h"
|
||||
@@ -271,12 +270,12 @@ TEST_F(WifiLanBwuHandlerTest, InitializeUpgradedMediumForEndpoint_Success) {
|
||||
address_candidate->set_port(8888);
|
||||
upgrade_path_info->set_supports_client_introduction_ack(true);
|
||||
|
||||
ByteArray result = handler_.InitializeUpgradedMediumForEndpoint(
|
||||
std::string result = handler_.InitializeUpgradedMediumForEndpoint(
|
||||
&client, std::string(kServiceId), std::string(kEndpointId));
|
||||
|
||||
EXPECT_FALSE(result.Empty());
|
||||
EXPECT_FALSE(result.empty());
|
||||
OfflineFrame result_frame;
|
||||
EXPECT_TRUE(result_frame.ParseFromString(std::string(result)));
|
||||
EXPECT_TRUE(result_frame.ParseFromString(result));
|
||||
EXPECT_THAT(result_frame, EqualsProto(expected_frame));
|
||||
|
||||
constexpr absl::string_view kClientSessionLog = R"pb(
|
||||
|
||||
Reference in New Issue
Block a user