BEGIN_PUBLIC

Microsoft has updated the winrt library
END_PUBLC

PiperOrigin-RevId: 387168248
This commit is contained in:
hai007
2021-07-29 03:27:37 -07:00
committed by Janusz Sobczak
parent 09e65aeddb
commit b1815095dd
1579 changed files with 967 additions and 20157 deletions
+11 -10
View File
@@ -1,3 +1,4 @@
licenses(["notice"])
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,13 +27,13 @@ cc_library(
],
deps = [
":core_types",
"//absl/strings",
"//absl/time",
"//absl/types:span",
"//core/internal",
"//platform/base",
"//platform/public:logging",
"//platform/public:types",
"//absl/strings",
"//absl/time",
"//absl/types:span",
],
)
@@ -53,12 +54,12 @@ cc_library(
"//core:__subpackages__",
],
deps = [
"//platform/base",
"//platform/base:util",
"//platform/public:types",
"//proto:connections_enums_portable_proto",
"//absl/strings",
"//absl/types:variant",
"//platform/base",
"//platform/base:util",
"//platform/public:types",
],
)
@@ -76,15 +77,15 @@ cc_test(
deps = [
":core",
":core_types",
"//testing/base/public:gunit_main",
"//absl/strings",
"//absl/time",
"//absl/types:variant",
"//core/internal",
"//core/internal:internal_test",
"//platform/base",
"//platform/impl/g3", # build_cleaner: keep
"//platform/public:logging",
"//platform/public:types",
"//testing/base/public:gunit_main",
"//absl/strings",
"//absl/time",
"//absl/types:variant",
],
)
+1 -1
View File
@@ -17,11 +17,11 @@
#include <cassert>
#include <vector>
#include "absl/time/clock.h"
#include "core/options.h"
#include "platform/base/feature_flags.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/logging.h"
#include "absl/time/clock.h"
namespace location {
namespace nearby {
+2 -2
View File
@@ -17,6 +17,8 @@
#include <string>
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "core/internal/client_proxy.h"
#include "core/internal/offline_service_controller.h"
#include "core/internal/service_controller.h"
@@ -24,8 +26,6 @@
#include "core/listeners.h"
#include "core/options.h"
#include "core/params.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
namespace location {
namespace nearby {
+3 -3
View File
@@ -14,13 +14,13 @@
#include "core/core.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/clock.h"
#include "core/internal/client_proxy.h"
#include "core/internal/mock_service_controller.h"
#include "core/internal/service_controller.h"
#include "platform/public/logging.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/clock.h"
namespace location {
namespace nearby {
+26 -25
View File
@@ -1,3 +1,4 @@
licenses(["notice"])
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -88,20 +89,8 @@ cc_library(
],
deps = [
":message_lite",
"//core:core_types",
"//core/internal/mediums",
"//core/internal/mediums:utils",
"//core/internal/mediums/webrtc",
"//proto/connections:offline_wire_formats_portable_proto",
"//platform/api:comm",
"//platform/base",
"//platform/base:cancellation_flag",
"//platform/base:util",
"//platform/public:comm",
"//platform/public:logging",
"//platform/public:types",
"//proto:connections_enums_portable_proto",
"//securegcm:ukey2",
"//absl/base:core_headers",
"//absl/container:btree",
"//absl/container:flat_hash_map",
@@ -111,6 +100,18 @@ cc_library(
"//absl/strings",
"//absl/time",
"//absl/types:span",
"//core:core_types",
"//core/internal/mediums",
"//core/internal/mediums:utils",
"//core/internal/mediums/webrtc",
"//platform/api:comm",
"//platform/base",
"//platform/base:cancellation_flag",
"//platform/base:util",
"//platform/public:comm",
"//platform/public:logging",
"//platform/public:types",
"//securegcm:ukey2",
],
)
@@ -144,13 +145,13 @@ cc_library(
],
deps = [
":internal",
"//testing/base/public:gunit",
"//absl/functional:bind_front",
"//absl/strings",
"//core:core_types",
"//platform/base",
"//platform/base:test_util",
"//platform/public:types",
"//testing/base/public:gunit",
"//absl/functional:bind_front",
"//absl/strings",
],
)
@@ -183,18 +184,8 @@ cc_test(
deps = [
":internal",
":internal_test",
"//core:core_types",
"//core/internal/mediums",
"//core/internal/mediums:utils",
"//proto/connections:offline_wire_formats_portable_proto",
"//platform/base",
"//platform/base:test_util",
"//platform/impl/g3", # build_cleaner: keep
"//platform/public:comm",
"//platform/public:logging",
"//platform/public:types",
"//proto:connections_enums_portable_proto",
"//securegcm:ukey2",
"//testing/base/public:gunit",
"//testing/base/public:gunit_main",
"//absl/container:flat_hash_set",
@@ -202,5 +193,15 @@ cc_test(
"//absl/synchronization",
"//absl/time",
"//absl/types:span",
"//core:core_types",
"//core/internal/mediums",
"//core/internal/mediums:utils",
"//platform/base",
"//platform/base:test_util",
"//platform/impl/g3", # build_cleaner: keep
"//platform/public:comm",
"//platform/public:logging",
"//platform/public:types",
"//securegcm:ukey2",
],
)
+2 -2
View File
@@ -19,6 +19,8 @@
#include <memory>
#include <string>
#include "absl/container/flat_hash_map.h"
#include "absl/time/clock.h"
#include "core/internal/bwu_handler.h"
#include "core/internal/client_proxy.h"
#include "core/internal/endpoint_channel_manager.h"
@@ -26,8 +28,6 @@
#include "platform/public/count_down_latch.h"
#include "platform/public/scheduled_executor.h"
#include "platform/public/single_thread_executor.h"
#include "absl/container/flat_hash_map.h"
#include "absl/time/clock.h"
namespace location {
namespace nearby {
+3 -3
View File
@@ -16,15 +16,15 @@
#include <cassert>
#include "proto/connections_enums.pb.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "core/internal/offline_frames.h"
#include "platform/base/byte_array.h"
#include "platform/base/exception.h"
#include "platform/public/logging.h"
#include "platform/public/mutex.h"
#include "platform/public/mutex_lock.h"
#include "proto/connections_enums.pb.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
namespace location {
namespace nearby {
+2 -2
View File
@@ -19,6 +19,8 @@
#include <memory>
#include <string>
#include "securegcm/d2d_connection_context_v1.h"
#include "absl/base/thread_annotations.h"
#include "core/internal/endpoint_channel.h"
#include "platform/base/byte_array.h"
#include "platform/base/input_stream.h"
@@ -27,8 +29,6 @@
#include "platform/public/condition_variable.h"
#include "platform/public/mutex.h"
#include "platform/public/system_clock.h"
#include "securegcm/d2d_connection_context_v1.h"
#include "absl/base/thread_annotations.h"
namespace location {
namespace nearby {
@@ -18,6 +18,13 @@
#include <string>
#include <utility>
#include "proto/connections_enums.pb.h"
#include "securegcm/d2d_connection_context_v1.h"
#include "securegcm/ukey2_handshake.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/synchronization/mutex.h"
#include "absl/time/time.h"
#include "core/internal/encryption_runner.h"
#include "core/internal/offline_frames.h"
#include "platform/base/byte_array.h"
@@ -29,13 +36,6 @@
#include "platform/public/multi_thread_executor.h"
#include "platform/public/pipe.h"
#include "platform/public/single_thread_executor.h"
#include "proto/connections_enums.pb.h"
#include "securegcm/d2d_connection_context_v1.h"
#include "securegcm/ukey2_handshake.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/synchronization/mutex.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
+6 -6
View File
@@ -20,17 +20,17 @@
#include <limits>
#include <memory>
#include "securegcm/d2d_connection_context_v1.h"
#include "securegcm/ukey2_handshake.h"
#include "absl/container/flat_hash_set.h"
#include "absl/strings/escaping.h"
#include "absl/types/span.h"
#include "core/internal/offline_frames.h"
#include "core/internal/pcp_handler.h"
#include "core/options.h"
#include "platform/base/bluetooth_utils.h"
#include "platform/public/logging.h"
#include "platform/public/system_clock.h"
#include "securegcm/d2d_connection_context_v1.h"
#include "securegcm/ukey2_handshake.h"
#include "absl/container/flat_hash_set.h"
#include "absl/strings/escaping.h"
#include "absl/types/span.h"
namespace location {
namespace nearby {
@@ -963,7 +963,7 @@ void BasePcpHandler::OnEndpointLost(
const auto* discovered_endpoint = GetDiscoveredEndpoint(endpoint.endpoint_id);
if (discovered_endpoint == nullptr) {
NEARBY_LOGS(INFO) << "No previous endpoint (nothing to lose): endpoint_id="
<< endpoint.endpoint_id;
<< endpoint.endpoint_id;
return;
}
+5 -5
View File
@@ -20,6 +20,11 @@
#include <string>
#include <vector>
#include "securegcm/d2d_connection_context_v1.h"
#include "securegcm/ukey2_handshake.h"
#include "absl/container/btree_map.h"
#include "absl/container/flat_hash_map.h"
#include "absl/time/time.h"
#include "core/internal/bwu_manager.h"
#include "core/internal/client_proxy.h"
#include "core/internal/encryption_runner.h"
@@ -42,11 +47,6 @@
#include "platform/public/scheduled_executor.h"
#include "platform/public/single_thread_executor.h"
#include "platform/public/system_clock.h"
#include "securegcm/d2d_connection_context_v1.h"
#include "securegcm/ukey2_handshake.h"
#include "absl/container/btree_map.h"
#include "absl/container/flat_hash_map.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
+5 -5
View File
@@ -18,6 +18,11 @@
#include <atomic>
#include <memory>
#include "proto/connections/offline_wire_formats.pb.h"
#include "proto/connections_enums.pb.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
#include "core/internal/base_endpoint_channel.h"
#include "core/internal/bwu_manager.h"
#include "core/internal/client_proxy.h"
@@ -26,16 +31,11 @@
#include "core/listeners.h"
#include "core/options.h"
#include "core/params.h"
#include "proto/connections/offline_wire_formats.pb.h"
#include "platform/base/byte_array.h"
#include "platform/base/exception.h"
#include "platform/base/medium_environment.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/pipe.h"
#include "proto/connections_enums.pb.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
+1 -1
View File
@@ -16,10 +16,10 @@
#include <inttypes.h>
#include "absl/strings/escaping.h"
#include "core/internal/base_pcp_handler.h"
#include "platform/base/base_input_stream.h"
#include "platform/public/logging.h"
#include "absl/strings/escaping.h"
namespace location {
namespace nearby {
+1 -2
View File
@@ -77,8 +77,7 @@ class BleAdvertisement {
const std::string& endpoint_id,
const ByteArray& endpoint_info,
const std::string& bluetooth_mac_address,
const ByteArray& uwb_address,
WebRtcState web_rtc_state);
const ByteArray& uwb_address, WebRtcState web_rtc_state);
BleAdvertisement(bool fast_advertisement,
const ByteArray& ble_advertisement_bytes);
BleAdvertisement(const BleAdvertisement&) = default;
+68 -123
View File
@@ -14,8 +14,8 @@
#include "core/internal/ble_advertisement.h"
#include "core/internal/base_pcp_handler.h"
#include "gtest/gtest.h"
#include "core/internal/base_pcp_handler.h"
namespace location {
namespace nearby {
@@ -36,14 +36,11 @@ constexpr WebRtcState kWebRtcState = WebRtcState::kConnectable;
TEST(BleAdvertisementTest, ConstructionWorks) {
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
ByteArray endpoint_info{std::string(kEndpointName)};
BleAdvertisement ble_advertisement{kVersion,
kPcp,
service_id_hash,
std::string(kEndpointId),
endpoint_info,
std::string(kBluetoothMacAddress),
ByteArray{},
kWebRtcState};
BleAdvertisement ble_advertisement{
kVersion, kPcp,
service_id_hash, std::string(kEndpointId),
endpoint_info, std::string(kBluetoothMacAddress),
ByteArray{}, kWebRtcState};
EXPECT_TRUE(ble_advertisement.IsValid());
EXPECT_FALSE(ble_advertisement.IsFastAdvertisement());
@@ -58,11 +55,8 @@ TEST(BleAdvertisementTest, ConstructionWorks) {
TEST(BleAdvertisementTest, ConstructionWorksForFastAdvertisement) {
ByteArray fast_endpoint_info{std::string(kFastAdvertisementEndpointName)};
BleAdvertisement ble_advertisement{kVersion,
kPcp,
std::string(kEndpointId),
fast_endpoint_info,
ByteArray{}};
BleAdvertisement ble_advertisement{kVersion, kPcp, std::string(kEndpointId),
fast_endpoint_info, ByteArray{}};
EXPECT_TRUE(ble_advertisement.IsValid());
EXPECT_TRUE(ble_advertisement.IsFastAdvertisement());
@@ -101,11 +95,8 @@ TEST(BleAdvertisementTest,
ConstructionWorksWithEmptyEndpointInfoForFastAdvertisement) {
ByteArray empty_endpoint_info;
BleAdvertisement ble_advertisement{kVersion,
kPcp,
std::string(kEndpointId),
empty_endpoint_info,
ByteArray{}};
BleAdvertisement ble_advertisement{kVersion, kPcp, std::string(kEndpointId),
empty_endpoint_info, ByteArray{}};
EXPECT_TRUE(ble_advertisement.IsValid());
EXPECT_TRUE(ble_advertisement.IsFastAdvertisement());
@@ -144,11 +135,8 @@ TEST(BleAdvertisementTest,
ConstructionWorksWithEmojiEndpointInfoForFastAdvertisement) {
ByteArray emoji_endpoint_info{std::string("\u0001F450 \u0001F450")};
BleAdvertisement ble_advertisement{kVersion,
kPcp,
std::string(kEndpointId),
emoji_endpoint_info,
ByteArray{}};
BleAdvertisement ble_advertisement{kVersion, kPcp, std::string(kEndpointId),
emoji_endpoint_info, ByteArray{}};
EXPECT_TRUE(ble_advertisement.IsValid());
EXPECT_TRUE(ble_advertisement.IsFastAdvertisement());
@@ -165,14 +153,11 @@ TEST(BleAdvertisementTest, ConstructionFailsWithLongEndpointInfo) {
ByteArray long_endpoint_info{long_endpoint_name};
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
BleAdvertisement ble_advertisement{kVersion,
kPcp,
service_id_hash,
std::string(kEndpointId),
long_endpoint_info,
std::string(kBluetoothMacAddress),
ByteArray{},
kWebRtcState};
BleAdvertisement ble_advertisement{
kVersion, kPcp,
service_id_hash, std::string(kEndpointId),
long_endpoint_info, std::string(kBluetoothMacAddress),
ByteArray{}, kWebRtcState};
EXPECT_FALSE(ble_advertisement.IsValid());
}
@@ -183,11 +168,8 @@ TEST(BleAdvertisementTest,
BleAdvertisement::kMaxFastEndpointInfoLength + 1, 'x');
ByteArray long_endpoint_info{long_endpoint_name};
BleAdvertisement ble_advertisement{kVersion,
kPcp,
std::string(kEndpointId),
long_endpoint_info,
ByteArray{}};
BleAdvertisement ble_advertisement{kVersion, kPcp, std::string(kEndpointId),
long_endpoint_info, ByteArray{}};
EXPECT_FALSE(ble_advertisement.IsValid());
}
@@ -197,14 +179,11 @@ TEST(BleAdvertisementTest, ConstructionFailsWithBadVersion) {
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
ByteArray endpoint_info{std::string(kEndpointName)};
BleAdvertisement ble_advertisement{bad_version,
kPcp,
service_id_hash,
std::string(kEndpointId),
endpoint_info,
std::string(kBluetoothMacAddress),
ByteArray{},
kWebRtcState};
BleAdvertisement ble_advertisement{
bad_version, kPcp,
service_id_hash, std::string(kEndpointId),
endpoint_info, std::string(kBluetoothMacAddress),
ByteArray{}, kWebRtcState};
EXPECT_FALSE(ble_advertisement.IsValid());
}
@@ -214,11 +193,9 @@ TEST(BleAdvertisementTest,
auto bad_version = static_cast<BleAdvertisement::Version>(666);
ByteArray fast_endpoint_info{std::string(kFastAdvertisementEndpointName)};
BleAdvertisement ble_advertisement{bad_version,
kPcp,
BleAdvertisement ble_advertisement{bad_version, kPcp,
std::string(kEndpointId),
fast_endpoint_info,
ByteArray{}};
fast_endpoint_info, ByteArray{}};
EXPECT_FALSE(ble_advertisement.IsValid());
}
@@ -228,14 +205,11 @@ TEST(BleAdvertisementTest, ConstructionFailsWithBadPCP) {
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
ByteArray endpoint_info{std::string(kEndpointName)};
BleAdvertisement ble_advertisement{kVersion,
bad_pcp,
service_id_hash,
std::string(kEndpointId),
endpoint_info,
std::string(kBluetoothMacAddress),
ByteArray{},
kWebRtcState};
BleAdvertisement ble_advertisement{
kVersion, bad_pcp,
service_id_hash, std::string(kEndpointId),
endpoint_info, std::string(kBluetoothMacAddress),
ByteArray{}, kWebRtcState};
EXPECT_FALSE(ble_advertisement.IsValid());
}
@@ -244,11 +218,9 @@ TEST(BleAdvertisementTest, ConstructionFailsWithBadPCPForFastAdvertisement) {
auto bad_pcp = static_cast<Pcp>(666);
ByteArray fast_endpoint_info{std::string(kFastAdvertisementEndpointName)};
BleAdvertisement ble_advertisement{kVersion,
bad_pcp,
BleAdvertisement ble_advertisement{kVersion, bad_pcp,
std::string(kEndpointId),
fast_endpoint_info,
ByteArray{}};
fast_endpoint_info, ByteArray{}};
EXPECT_FALSE(ble_advertisement.IsValid());
}
@@ -258,14 +230,11 @@ TEST(BleAdvertisementTest, ConstructionSucceedsWithEmptyBluetoothMacAddress) {
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
ByteArray endpoint_info{std::string(kEndpointName)};
BleAdvertisement ble_advertisement{kVersion,
kPcp,
service_id_hash,
std::string(kEndpointId),
endpoint_info,
empty_bluetooth_mac_address,
ByteArray{},
kWebRtcState};
BleAdvertisement ble_advertisement{
kVersion, kPcp,
service_id_hash, std::string(kEndpointId),
endpoint_info, empty_bluetooth_mac_address,
ByteArray{}, kWebRtcState};
EXPECT_TRUE(ble_advertisement.IsValid());
}
@@ -275,14 +244,10 @@ TEST(BleAdvertisementTest, ConstructionSucceedsWithInvalidBluetoothMacAddress) {
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
ByteArray endpoint_info{std::string(kEndpointName)};
BleAdvertisement ble_advertisement{kVersion,
kPcp,
service_id_hash,
std::string(kEndpointId),
endpoint_info,
bad_bluetooth_mac_address,
ByteArray{},
kWebRtcState};
BleAdvertisement ble_advertisement{kVersion, kPcp,
service_id_hash, std::string(kEndpointId),
endpoint_info, bad_bluetooth_mac_address,
ByteArray{}, kWebRtcState};
EXPECT_TRUE(ble_advertisement.IsValid());
EXPECT_EQ(kVersion, ble_advertisement.GetVersion());
@@ -298,14 +263,11 @@ TEST(BleAdvertisementTest, ConstructionFromBytesWorks) {
// Serialize good data into a good Ble Advertisement.
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
ByteArray endpoint_info{std::string(kEndpointName)};
BleAdvertisement org_ble_advertisement{kVersion,
kPcp,
service_id_hash,
std::string(kEndpointId),
endpoint_info,
std::string(kBluetoothMacAddress),
ByteArray{},
kWebRtcState};
BleAdvertisement org_ble_advertisement{
kVersion, kPcp,
service_id_hash, std::string(kEndpointId),
endpoint_info, std::string(kBluetoothMacAddress),
ByteArray{}, kWebRtcState};
ByteArray ble_advertisement_bytes(org_ble_advertisement);
BleAdvertisement ble_advertisement{false, ble_advertisement_bytes};
@@ -324,11 +286,9 @@ TEST(BleAdvertisementTest, ConstructionFromBytesWorks) {
TEST(BleAdvertisementTest, ConstructionFromBytesWorksForFastAdvertisement) {
// Serialize good data into a good Ble Advertisement.
ByteArray fast_endpoint_info{std::string(kFastAdvertisementEndpointName)};
BleAdvertisement org_ble_advertisement{kVersion,
kPcp,
BleAdvertisement org_ble_advertisement{kVersion, kPcp,
std::string(kEndpointId),
fast_endpoint_info,
ByteArray{}};
fast_endpoint_info, ByteArray{}};
ByteArray ble_advertisement_bytes(org_ble_advertisement);
BleAdvertisement ble_advertisement{true, ble_advertisement_bytes};
@@ -348,14 +308,11 @@ TEST(BleAdvertisementTest, ConstructionFromLongLengthBytesWorks) {
// Serialize good data into a good Ble Advertisement.
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
ByteArray endpoint_info{std::string(kEndpointName)};
BleAdvertisement ble_advertisement{kVersion,
kPcp,
service_id_hash,
std::string(kEndpointId),
endpoint_info,
std::string(kBluetoothMacAddress),
ByteArray{},
kWebRtcState};
BleAdvertisement ble_advertisement{
kVersion, kPcp,
service_id_hash, std::string(kEndpointId),
endpoint_info, std::string(kBluetoothMacAddress),
ByteArray{}, kWebRtcState};
ByteArray ble_advertisement_bytes(ble_advertisement);
// Add bytes to the end of the valid Ble advertisement.
@@ -395,14 +352,11 @@ TEST(BleAdvertisementTest, ConstructionFromShortLengthBytesFails) {
// Serialize good data into a good Ble Advertisement.
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
ByteArray endpoint_info{std::string(kEndpointName)};
BleAdvertisement ble_advertisement{kVersion,
kPcp,
service_id_hash,
std::string(kEndpointId),
endpoint_info,
std::string(kBluetoothMacAddress),
ByteArray{},
kWebRtcState};
BleAdvertisement ble_advertisement{
kVersion, kPcp,
service_id_hash, std::string(kEndpointId),
endpoint_info, std::string(kBluetoothMacAddress),
ByteArray{}, kWebRtcState};
ByteArray ble_advertisement_bytes(ble_advertisement);
// Shorten the valid Ble Advertisement.
@@ -420,11 +374,8 @@ TEST(BleAdvertisementTest,
ConstructionFromShortLengthBytesFailsForFastAdvertisement) {
// Serialize good data into a good Ble Advertisement.
ByteArray fast_endpoint_info{std::string(kFastAdvertisementEndpointName)};
BleAdvertisement ble_advertisement{kVersion,
kPcp,
std::string(kEndpointId),
fast_endpoint_info,
ByteArray{}};
BleAdvertisement ble_advertisement{kVersion, kPcp, std::string(kEndpointId),
fast_endpoint_info, ByteArray{}};
ByteArray ble_advertisement_bytes(ble_advertisement);
// Shorten the valid Ble Advertisement.
@@ -442,14 +393,11 @@ TEST(BleAdvertisementTest,
// Serialize good data into a good Ble Advertisement.
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
ByteArray endpoint_info{std::string(kEndpointName)};
BleAdvertisement ble_advertisement{kVersion,
kPcp,
service_id_hash,
std::string(kEndpointId),
endpoint_info,
std::string(kBluetoothMacAddress),
ByteArray{},
kWebRtcState};
BleAdvertisement ble_advertisement{
kVersion, kPcp,
service_id_hash, std::string(kEndpointId),
endpoint_info, std::string(kBluetoothMacAddress),
ByteArray{}, kWebRtcState};
ByteArray ble_advertisement_bytes(ble_advertisement);
// Corrupt the EndpointNameLength bits.
@@ -467,11 +415,8 @@ TEST(BleAdvertisementTest,
ConstructionFromByesWithWrongEndpointInfoLengthFailsForFastAdvertisement) {
// Serialize good data into a good Ble Advertisement.
ByteArray fast_endpoint_info{std::string(kFastAdvertisementEndpointName)};
BleAdvertisement ble_advertisement{kVersion,
kPcp,
std::string(kEndpointId),
fast_endpoint_info,
ByteArray{}};
BleAdvertisement ble_advertisement{kVersion, kPcp, std::string(kEndpointId),
fast_endpoint_info, ByteArray{}};
ByteArray ble_advertisement_bytes = ByteArray(ble_advertisement);
// Corrupt the EndpointInfoLength bits.
+1 -1
View File
@@ -14,10 +14,10 @@
#include "core/internal/bluetooth_bwu_handler.h"
#include "absl/functional/bind_front.h"
#include "core/internal/bluetooth_endpoint_channel.h"
#include "core/internal/client_proxy.h"
#include "core/internal/offline_frames.h"
#include "absl/functional/bind_front.h"
// Manages the Bluetooth-specific methods needed to upgrade an {@link
// EndpointChannel}.
+2 -3
View File
@@ -19,11 +19,11 @@
#include <cstring>
#include <utility>
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "platform/base/base64_utils.h"
#include "platform/base/base_input_stream.h"
#include "platform/public/logging.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
namespace location {
namespace nearby {
@@ -107,7 +107,6 @@ BluetoothDeviceName::BluetoothDeviceName(
// The next 3 bytes are supposed to be the service_id_hash.
service_id_hash_ = base_input_stream.ReadBytes(kServiceIdHashLength);
// The next 1 byte is field containning WebRtc state.
auto field_byte = static_cast<char>(base_input_stream.ReadUint8());
web_rtc_state_ = (field_byte & kWebRtcConnectableFlagBitmask) == 1
+2 -3
View File
@@ -17,10 +17,10 @@
#include <cstdint>
#include "absl/strings/string_view.h"
#include "core/internal/base_pcp_handler.h"
#include "core/internal/pcp.h"
#include "platform/base/byte_array.h"
#include "absl/strings/string_view.h"
namespace location {
namespace nearby {
@@ -46,8 +46,7 @@ class BluetoothDeviceName {
BluetoothDeviceName(Version version, Pcp pcp, absl::string_view endpoint_id,
const ByteArray& service_id_hash,
const ByteArray& endpoint_info,
const ByteArray& uwb_address,
WebRtcState web_rtc_state);
const ByteArray& uwb_address, WebRtcState web_rtc_state);
explicit BluetoothDeviceName(absl::string_view bluetooth_device_name_string);
BluetoothDeviceName(const BluetoothDeviceName&) = default;
BluetoothDeviceName& operator=(const BluetoothDeviceName&) = default;
+27 -63
View File
@@ -17,8 +17,8 @@
#include <cstring>
#include <memory>
#include "platform/base/base64_utils.h"
#include "gtest/gtest.h"
#include "platform/base/base64_utils.h"
namespace location {
namespace nearby {
@@ -37,13 +37,9 @@ constexpr WebRtcState kWebRtcState = WebRtcState::kConnectable;
TEST(BluetoothDeviceNameTest, ConstructionWorks) {
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
ByteArray endpoint_info{std::string(kEndPointName)};
BluetoothDeviceName bluetooth_device_name{kVersion,
kPcp,
kEndPointID,
service_id_hash,
endpoint_info,
ByteArray{},
kWebRtcState};
BluetoothDeviceName bluetooth_device_name{
kVersion, kPcp, kEndPointID, service_id_hash,
endpoint_info, ByteArray{}, kWebRtcState};
EXPECT_TRUE(bluetooth_device_name.IsValid());
EXPECT_EQ(kVersion, bluetooth_device_name.GetVersion());
@@ -80,13 +76,9 @@ TEST(BluetoothDeviceNameTest, ConstructionFailsWithBadVersion) {
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
ByteArray endpoint_info{std::string(kEndPointName)};
BluetoothDeviceName bluetooth_device_name{bad_version,
kPcp,
kEndPointID,
service_id_hash,
endpoint_info,
ByteArray{},
kWebRtcState};
BluetoothDeviceName bluetooth_device_name{
bad_version, kPcp, kEndPointID, service_id_hash,
endpoint_info, ByteArray{}, kWebRtcState};
EXPECT_FALSE(bluetooth_device_name.IsValid());
}
@@ -96,13 +88,9 @@ TEST(BluetoothDeviceNameTest, ConstructionFailsWithBadPcp) {
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
ByteArray endpoint_info{std::string(kEndPointName)};
BluetoothDeviceName bluetooth_device_name{kVersion,
bad_pcp,
kEndPointID,
service_id_hash,
endpoint_info,
ByteArray{},
kWebRtcState};
BluetoothDeviceName bluetooth_device_name{
kVersion, bad_pcp, kEndPointID, service_id_hash,
endpoint_info, ByteArray{}, kWebRtcState};
EXPECT_FALSE(bluetooth_device_name.IsValid());
}
@@ -112,13 +100,9 @@ TEST(BluetoothDeviceNameTest, ConstructionFailsWithShortEndpointId) {
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
ByteArray endpoint_info{std::string(kEndPointName)};
BluetoothDeviceName bluetooth_device_name{kVersion,
kPcp,
short_endpoint_id,
service_id_hash,
endpoint_info,
ByteArray{},
kWebRtcState};
BluetoothDeviceName bluetooth_device_name{
kVersion, kPcp, short_endpoint_id, service_id_hash,
endpoint_info, ByteArray{}, kWebRtcState};
EXPECT_FALSE(bluetooth_device_name.IsValid());
}
@@ -128,13 +112,9 @@ TEST(BluetoothDeviceNameTest, ConstructionFailsWithLongEndpointId) {
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
ByteArray endpoint_info{std::string(kEndPointName)};
BluetoothDeviceName bluetooth_device_name{kVersion,
kPcp,
long_endpoint_id,
service_id_hash,
endpoint_info,
ByteArray{},
kWebRtcState};
BluetoothDeviceName bluetooth_device_name{
kVersion, kPcp, long_endpoint_id, service_id_hash,
endpoint_info, ByteArray{}, kWebRtcState};
EXPECT_FALSE(bluetooth_device_name.IsValid());
}
@@ -144,13 +124,9 @@ TEST(BluetoothDeviceNameTest, ConstructionFailsWithShortServiceIdHash) {
ByteArray short_service_id_hash{short_service_id_hash_bytes};
ByteArray endpoint_info{std::string(kEndPointName)};
BluetoothDeviceName bluetooth_device_name{kVersion,
kPcp,
kEndPointID,
short_service_id_hash,
endpoint_info,
ByteArray{},
kWebRtcState};
BluetoothDeviceName bluetooth_device_name{
kVersion, kPcp, kEndPointID, short_service_id_hash,
endpoint_info, ByteArray{}, kWebRtcState};
EXPECT_FALSE(bluetooth_device_name.IsValid());
}
@@ -160,13 +136,9 @@ TEST(BluetoothDeviceNameTest, ConstructionFailsWithLongServiceIdHash) {
ByteArray long_service_id_hash{long_service_id_hash_bytes};
ByteArray endpoint_info{std::string(kEndPointName)};
BluetoothDeviceName bluetooth_device_name{kVersion,
kPcp,
kEndPointID,
long_service_id_hash,
endpoint_info,
ByteArray{},
kWebRtcState};
BluetoothDeviceName bluetooth_device_name{
kVersion, kPcp, kEndPointID, long_service_id_hash,
endpoint_info, ByteArray{}, kWebRtcState};
EXPECT_FALSE(bluetooth_device_name.IsValid());
}
@@ -185,13 +157,9 @@ TEST(BluetoothDeviceNameTest, ConstructionFailsWithWrongEndpointNameLength) {
// Serialize good data into a good Bluetooth Device Name.
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
ByteArray endpoint_info{std::string(kEndPointName)};
BluetoothDeviceName bluetooth_device_name{kVersion,
kPcp,
kEndPointID,
service_id_hash,
endpoint_info,
ByteArray{},
kWebRtcState};
BluetoothDeviceName bluetooth_device_name{
kVersion, kPcp, kEndPointID, service_id_hash,
endpoint_info, ByteArray{}, kWebRtcState};
auto bluetooth_device_name_string = std::string(bluetooth_device_name);
// Base64-decode the good Bluetooth Device Name.
@@ -218,12 +186,8 @@ TEST(BluetoothDeviceNameTest, CanParseGeneratedName) {
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
ByteArray endpoint_info{std::string(kEndPointName)};
// Build name1 from scratch.
BluetoothDeviceName name1{kVersion,
kPcp,
kEndPointID,
service_id_hash,
endpoint_info,
ByteArray{},
BluetoothDeviceName name1{kVersion, kPcp, kEndPointID,
service_id_hash, endpoint_info, ByteArray{},
kWebRtcState};
// Build name2 from string composed from name1.
BluetoothDeviceName name2{std::string(name1)};
+7 -7
View File
@@ -17,6 +17,9 @@
#include <algorithm>
#include <memory>
#include "proto/connections_enums.pb.h"
#include "absl/functional/bind_front.h"
#include "absl/time/time.h"
#include "core/internal/bluetooth_bwu_handler.h"
#include "core/internal/bwu_handler.h"
#include "core/internal/offline_frames.h"
@@ -25,9 +28,6 @@
#include "platform/base/byte_array.h"
#include "platform/base/feature_flags.h"
#include "platform/public/count_down_latch.h"
#include "proto/connections_enums.pb.h"
#include "absl/functional/bind_front.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
@@ -187,10 +187,10 @@ void BwuManager::InitiateBwuForEndpoint(ClientProxy* client,
// connects over Bluetooth, and is not connected to LAN. Bluetooth is the
// best medium, and we attempt to upgrade from Bluetooth to Bluetooth.
// if (medium_ == channel->GetMedium()) {
NEARBY_LOGS(INFO) << "BwuManager ignoring the upgrade for endpoint "
<< endpoint_id
<< " because it is already connected over medium "
<< proto::connections::Medium_Name(medium_);
NEARBY_LOGS(INFO) << "BwuManager ignoring the upgrade for endpoint "
<< endpoint_id
<< " because it is already connected over medium "
<< proto::connections::Medium_Name(medium_);
if (medium_ == channel->GetMedium()) {
return;
}
+3 -3
View File
@@ -19,6 +19,9 @@
#include <string>
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/time/time.h"
#include "core/internal/bwu_handler.h"
#include "core/internal/client_proxy.h"
#include "core/internal/endpoint_manager.h"
@@ -26,9 +29,6 @@
#include "core/options.h"
#include "platform/base/byte_array.h"
#include "platform/public/scheduled_executor.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
+3 -3
View File
@@ -16,6 +16,9 @@
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
#include "core/internal/client_proxy.h"
#include "core/internal/endpoint_channel_manager.h"
#include "core/internal/endpoint_manager.h"
@@ -23,9 +26,6 @@
#include "core/internal/mediums/utils.h"
#include "core/internal/offline_frames.h"
#include "platform/public/system_clock.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
+4 -4
View File
@@ -18,15 +18,15 @@
#include <limits>
#include <utility>
#include "platform/base/feature_flags.h"
#include "platform/base/prng.h"
#include "platform/public/logging.h"
#include "platform/public/mutex_lock.h"
#include "proto/connections_enums.pb.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "platform/base/feature_flags.h"
#include "platform/base/prng.h"
#include "platform/public/logging.h"
#include "platform/public/mutex_lock.h"
namespace location {
namespace nearby {
+6 -6
View File
@@ -16,18 +16,18 @@
#include <string>
#include "core/listeners.h"
#include "core/options.h"
#include "core/strategy.h"
#include "platform/base/byte_array.h"
#include "platform/base/feature_flags.h"
#include "platform/base/medium_environment.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/container/flat_hash_set.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "absl/types/span.h"
#include "core/listeners.h"
#include "core/options.h"
#include "core/strategy.h"
#include "platform/base/byte_array.h"
#include "platform/base/feature_flags.h"
#include "platform/base/medium_environment.h"
namespace location {
namespace nearby {
+4 -4
View File
@@ -18,15 +18,15 @@
#include <cstdint>
#include <memory>
#include "securegcm/ukey2_handshake.h"
#include "absl/strings/ascii.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "platform/base/base64_utils.h"
#include "platform/base/byte_array.h"
#include "platform/base/exception.h"
#include "platform/public/cancelable_alarm.h"
#include "platform/public/logging.h"
#include "securegcm/ukey2_handshake.h"
#include "absl/strings/ascii.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
+1 -1
View File
@@ -17,13 +17,13 @@
#include <string>
#include "securegcm/ukey2_handshake.h"
#include "core/internal/client_proxy.h"
#include "core/internal/endpoint_channel.h"
#include "core/listeners.h"
#include "platform/base/byte_array.h"
#include "platform/public/scheduled_executor.h"
#include "platform/public/single_thread_executor.h"
#include "securegcm/ukey2_handshake.h"
namespace location {
namespace nearby {
+4 -4
View File
@@ -14,16 +14,16 @@
#include "core/internal/encryption_runner.h"
#include "proto/connections_enums.pb.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/clock.h"
#include "core/internal/client_proxy.h"
#include "core/internal/endpoint_channel.h"
#include "platform/base/byte_array.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/pipe.h"
#include "platform/public/system_clock.h"
#include "proto/connections_enums.pb.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/clock.h"
namespace location {
namespace nearby {
+3 -3
View File
@@ -18,12 +18,12 @@
#include <cstdint>
#include <string>
#include "platform/base/byte_array.h"
#include "platform/base/exception.h"
#include "platform/public/mutex.h"
#include "proto/connections_enums.pb.h"
#include "securegcm/d2d_connection_context_v1.h"
#include "absl/time/clock.h"
#include "platform/base/byte_array.h"
#include "platform/base/exception.h"
#include "platform/public/mutex.h"
namespace location {
namespace nearby {
@@ -18,14 +18,14 @@
#include <string>
#include <utility>
#include "core/internal/offline_frames.h"
#include "proto/connections/offline_wire_formats.pb.h"
#include "absl/time/time.h"
#include "core/internal/offline_frames.h"
#include "platform/base/feature_flags.h"
#include "platform/public/logging.h"
#include "platform/public/mutex.h"
#include "platform/public/mutex_lock.h"
#include "platform/public/system_clock.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
+2 -2
View File
@@ -18,12 +18,12 @@
#include <memory>
#include <string>
#include "securegcm/d2d_connection_context_v1.h"
#include "absl/container/flat_hash_map.h"
#include "core/internal/client_proxy.h"
#include "core/internal/endpoint_channel.h"
#include "platform/public/logging.h"
#include "platform/public/mutex.h"
#include "securegcm/d2d_connection_context_v1.h"
#include "absl/container/flat_hash_map.h"
namespace location {
namespace nearby {
+1 -1
View File
@@ -17,9 +17,9 @@
#include <memory>
#include <utility>
#include "proto/connections/offline_wire_formats.pb.h"
#include "core/internal/endpoint_channel.h"
#include "core/internal/offline_frames.h"
#include "proto/connections/offline_wire_formats.pb.h"
#include "platform/base/exception.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/logging.h"
+4 -4
View File
@@ -18,6 +18,10 @@
#include <cstdint>
#include <memory>
#include "absl/base/thread_annotations.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/time/time.h"
#include "core/internal/client_proxy.h"
#include "core/internal/endpoint_channel.h"
#include "core/internal/endpoint_channel_manager.h"
@@ -28,10 +32,6 @@
#include "platform/public/multi_thread_executor.h"
#include "platform/public/single_thread_executor.h"
#include "platform/public/system_clock.h"
#include "absl/base/thread_annotations.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
+6 -6
View File
@@ -19,6 +19,12 @@
#include <string>
#include <utility>
#include "proto/connections_enums.pb.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/synchronization/mutex.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "core/internal/client_proxy.h"
#include "core/internal/endpoint_channel_manager.h"
#include "core/internal/offline_frames.h"
@@ -28,12 +34,6 @@
#include "platform/public/count_down_latch.h"
#include "platform/public/logging.h"
#include "platform/public/pipe.h"
#include "proto/connections_enums.pb.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/synchronization/mutex.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
+4 -3
View File
@@ -1,3 +1,6 @@
load("//security/fuzzing/blaze:cc_fuzz_target.bzl", "cc_fuzz_target")
licenses(["notice"])
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,15 +15,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("//security/fuzzing/blaze:cc_fuzz_target.bzl", "cc_fuzz_target")
cc_fuzz_target(
name = "offline_frames_fuzzer",
srcs = ["offline_frames_fuzzer.cc"],
componentid = 148515,
deps = [
"//security/fuzzing/blaze:default_init_google_for_cc_fuzz_target",
"//core/internal",
"//platform/base",
"//security/fuzzing/blaze:default_init_google_for_cc_fuzz_target",
],
)
@@ -36,13 +36,9 @@ class InjectedBluetoothDevice : public api::BluetoothDevice {
~InjectedBluetoothDevice() override = default;
// api::BluetoothDevice:
std::string GetName() const override {
return name_;
}
std::string GetName() const override { return name_; }
std::string GetMacAddress() const override {
return mac_address_;
}
std::string GetMacAddress() const override { return mac_address_; }
private:
const std::string name_;
@@ -55,13 +51,10 @@ InjectedBluetoothDeviceStore::InjectedBluetoothDeviceStore() = default;
InjectedBluetoothDeviceStore::~InjectedBluetoothDeviceStore() = default;
BluetoothDevice
InjectedBluetoothDeviceStore::CreateInjectedBluetoothDevice(
BluetoothDevice InjectedBluetoothDeviceStore::CreateInjectedBluetoothDevice(
const ByteArray& remote_bluetooth_mac_address,
const std::string& endpoint_id,
const ByteArray& endpoint_info,
const ByteArray& service_id_hash,
Pcp pcp) {
const std::string& endpoint_id, const ByteArray& endpoint_info,
const ByteArray& service_id_hash, Pcp pcp) {
std::string remote_bluetooth_mac_address_str =
BluetoothUtils::ToString(remote_bluetooth_mac_address);
@@ -70,22 +63,17 @@ InjectedBluetoothDeviceStore::CreateInjectedBluetoothDevice(
return BluetoothDevice(/*device=*/nullptr);
// Non-empty endpoint info is required.
if (endpoint_info.Empty())
return BluetoothDevice(/*device=*/nullptr);
if (endpoint_info.Empty()) return BluetoothDevice(/*device=*/nullptr);
BluetoothDeviceName name(BluetoothDeviceName::Version::kV1,
pcp,
endpoint_id,
service_id_hash,
endpoint_info,
BluetoothDeviceName name(BluetoothDeviceName::Version::kV1, pcp, endpoint_id,
service_id_hash, endpoint_info,
/*uwb_address=*/ByteArray(),
WebRtcState::kConnectable);
// Note: BluetoothDeviceName internally verifies that |endpoint_id| and
// |service_id_hash| are valid; the check below will fail if they are
// malformed.
if (!name.IsValid())
return BluetoothDevice(/*device=*/nullptr);
if (!name.IsValid()) return BluetoothDevice(/*device=*/nullptr);
auto injected_device = std::make_unique<InjectedBluetoothDevice>(
static_cast<std::string>(name), remote_bluetooth_mac_address_str);
@@ -51,10 +51,8 @@ class InjectedBluetoothDeviceStore {
// deleted.
BluetoothDevice CreateInjectedBluetoothDevice(
const ByteArray& remote_bluetooth_mac_address,
const std::string& endpoint_id,
const ByteArray& endpoint_info,
const ByteArray& service_id_hash,
Pcp pcp);
const std::string& endpoint_id, const ByteArray& endpoint_info,
const ByteArray& service_id_hash, Pcp pcp);
private:
// Devices created by this class. BluetoothDevice objects returned by
@@ -16,20 +16,20 @@
#include <array>
#include "gtest/gtest.h"
#include "core/internal/bluetooth_device_name.h"
#include "platform/base/bluetooth_utils.h"
#include "platform/base/byte_array.h"
#include "platform/public/bluetooth_adapter.h"
#include "gtest/gtest.h"
namespace location {
namespace nearby {
namespace connections {
namespace {
constexpr std::array<char, 6>
kTestRemoteBluetoothMacAddress{0x01, 0x23, 0x45, 0x67, 0x89, 0xab};
constexpr std::array<char, 2> kTestEndpointInfo {0xcd, 0xef};
constexpr std::array<char, 6> kTestRemoteBluetoothMacAddress{0x01, 0x23, 0x45,
0x67, 0x89, 0xab};
constexpr std::array<char, 2> kTestEndpointInfo{0xcd, 0xef};
constexpr std::array<char, 3> kTestServiceIdHash{0x01, 0x23, 0x45};
const char kTestEndpointId[] = "abcd";
+1 -3
View File
@@ -24,9 +24,7 @@ constexpr int InternalPayload::kIndeterminateSize;
InternalPayload::InternalPayload(Payload payload)
: payload_(std::move(payload)), payload_id_(payload_.GetId()) {}
Payload InternalPayload::ReleasePayload() {
return std::move(payload_);
}
Payload InternalPayload::ReleasePayload() { return std::move(payload_); }
Payload::Id InternalPayload::GetId() const { return payload_id_; }
@@ -17,6 +17,7 @@
#include <cstdint>
#include <memory>
#include "absl/memory/memory.h"
#include "core/payload.h"
#include "platform/base/byte_array.h"
#include "platform/base/exception.h"
@@ -25,7 +26,6 @@
#include "platform/public/logging.h"
#include "platform/public/mutex.h"
#include "platform/public/pipe.h"
#include "absl/memory/memory.h"
namespace location {
namespace nearby {
@@ -17,12 +17,12 @@
#include <string>
#include <utility>
#include "core/internal/offline_frames.h"
#include "proto/connections/offline_wire_formats.pb.h"
#include "platform/base/byte_array.h"
#include "platform/public/pipe.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "core/internal/offline_frames.h"
#include "platform/base/byte_array.h"
#include "platform/public/pipe.h"
namespace location {
namespace nearby {
+14 -13
View File
@@ -1,3 +1,4 @@
licenses(["notice"])
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -40,15 +41,7 @@ cc_library(
],
deps = [
":utils",
"//core:core_types",
"//core/internal/mediums/ble_v2",
"//core/internal/mediums/webrtc",
"//proto/connections:offline_wire_formats_portable_proto",
"//platform/base",
"//platform/base:cancellation_flag",
"//platform/public:comm",
"//platform/public:logging",
"//platform/public:types",
"//location/nearby/mediums/proto:web_rtc_signaling_frames_cc_proto",
"//absl/container:flat_hash_map",
"//absl/container:flat_hash_set",
@@ -56,6 +49,14 @@ cc_library(
"//absl/numeric:int128",
"//absl/strings",
"//absl/time",
"//core:core_types",
"//core/internal/mediums/ble_v2",
"//core/internal/mediums/webrtc",
"//platform/base",
"//platform/base:cancellation_flag",
"//platform/public:comm",
"//platform/public:logging",
"//platform/public:types",
"//smhasher:libmurmur3",
"//webrtc/api:libjingle_peerconnection_api",
"//webrtc/api:scoped_refptr",
@@ -93,13 +94,13 @@ cc_test(
shard_count = 16,
deps = [
":mediums",
"//testing/base/public:gunit_main",
"//absl/strings",
"//absl/time",
"//platform/base:test_util",
"//platform/impl/g3", # build_cleaner: keep
"//platform/public:comm",
"//platform/public:types",
"//testing/base/public:gunit_main",
"//absl/strings",
"//absl/time",
],
)
@@ -113,12 +114,12 @@ cc_test(
tags = ["notsan"], # NOTE(b/139734036): known data race in usrsctplib.
deps = [
":mediums",
"//testing/base/public:gunit_main",
"//absl/strings",
"//core/internal/mediums/webrtc",
"//platform/base",
"//platform/base:test_util",
"//platform/impl/g3", # build_cleaner: keep
"//platform/public:types",
"//testing/base/public:gunit_main",
"//absl/strings",
],
)
+1 -1
View File
@@ -18,12 +18,12 @@
#include <string>
#include <utility>
#include "absl/strings/escaping.h"
#include "core/internal/mediums/ble_v2/ble_advertisement.h"
#include "core/internal/mediums/utils.h"
#include "platform/base/prng.h"
#include "platform/public/logging.h"
#include "platform/public/mutex_lock.h"
#include "absl/strings/escaping.h"
namespace location {
namespace nearby {
+2 -2
View File
@@ -18,6 +18,8 @@
#include <cstdint>
#include <string>
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "core/internal/mediums/bluetooth_radio.h"
#include "core/listeners.h"
#include "platform/base/byte_array.h"
@@ -25,8 +27,6 @@
#include "platform/public/ble.h"
#include "platform/public/multi_thread_executor.h"
#include "platform/public/mutex.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
namespace location {
namespace nearby {
+2 -2
View File
@@ -16,13 +16,13 @@
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "core/internal/mediums/bluetooth_radio.h"
#include "platform/base/medium_environment.h"
#include "platform/public/ble.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/logging.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
namespace location {
namespace nearby {
+7 -6
View File
@@ -1,3 +1,4 @@
licenses(["notice"])
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,15 +33,15 @@ cc_library(
"//core/internal:__subpackages__",
],
deps = [
"//absl/container:flat_hash_map",
"//absl/container:flat_hash_set",
"//absl/strings",
"//absl/time",
"//core:core_types",
"//platform/base",
"//platform/base:util",
"//platform/public:logging",
"//platform/public:types",
"//absl/container:flat_hash_map",
"//absl/container:flat_hash_set",
"//absl/strings",
"//absl/time",
],
)
@@ -55,9 +56,9 @@ cc_test(
],
deps = [
":ble_v2",
"//platform/base",
"//platform/impl/g3", # buildcleaner: keep
"//testing/base/public:gunit_main",
"//absl/time",
"//platform/base",
"//platform/impl/g3", # buildcleaner: keep
],
)
@@ -17,9 +17,9 @@
#include <algorithm>
#include <vector>
#include "platform/public/mutex_lock.h"
#include "absl/container/flat_hash_set.h"
#include "absl/time/clock.h"
#include "platform/public/mutex_lock.h"
namespace location {
namespace nearby {
@@ -18,12 +18,12 @@
#include <cstdint>
#include <vector>
#include "platform/base/byte_array.h"
#include "platform/public/mutex.h"
#include "platform/public/system_clock.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/time/clock.h"
#include "platform/base/byte_array.h"
#include "platform/public/mutex.h"
#include "platform/public/system_clock.h"
namespace location {
namespace nearby {
@@ -16,9 +16,9 @@
#include <inttypes.h>
#include "absl/strings/str_cat.h"
#include "platform/base/base_input_stream.h"
#include "platform/public/logging.h"
#include "absl/strings/str_cat.h"
namespace location {
namespace nearby {
@@ -86,8 +86,7 @@ BleAdvertisement::BleAdvertisement(const ByteArray &ble_advertisement_bytes) {
BaseInputStream base_input_stream{advertisement_bytes};
// The first 1 byte is supposed to be the version, socket version and the fast
// advertisement flag.
auto version_byte =
static_cast<char>(base_input_stream.ReadUint8());
auto version_byte = static_cast<char>(base_input_stream.ReadUint8());
// Version.
version_ = static_cast<Version>((version_byte & kVersionBitmask) >> 5);
@@ -177,18 +176,14 @@ BleAdvertisement::operator ByteArray() const {
// clang-format on
if (fast_advertisement_) {
std::string out =
absl::StrCat(std::string(1, version_byte),
std::string(data_size_bytes),
std::string(data_),
std::string(device_token_));
absl::StrCat(std::string(1, version_byte), std::string(data_size_bytes),
std::string(data_), std::string(device_token_));
return ByteArray{std::move(out)};
} else {
std::string out =
absl::StrCat(std::string(1, version_byte),
std::string(service_id_hash_),
std::string(data_size_bytes),
std::string(data_),
std::string(device_token_));
std::string out = absl::StrCat(
std::string(1, version_byte), std::string(service_id_hash_),
std::string(data_size_bytes), std::string(data_),
std::string(device_token_));
return ByteArray{std::move(out)};
}
// clang-format on
@@ -16,10 +16,10 @@
#include <inttypes.h>
#include "absl/strings/str_cat.h"
#include "platform/base/base64_utils.h"
#include "platform/base/base_input_stream.h"
#include "platform/public/logging.h"
#include "absl/strings/str_cat.h"
namespace location {
namespace nearby {
@@ -14,8 +14,8 @@
#include "core/internal/mediums/ble_v2/ble_advertisement_header.h"
#include "platform/base/base64_utils.h"
#include "gtest/gtest.h"
#include "platform/base/base64_utils.h"
namespace location {
namespace nearby {
@@ -46,9 +46,7 @@ TEST(BleAdvertisementTest, ConstructionWorksV1) {
BleAdvertisement ble_advertisement{BleAdvertisement::Version::kV1,
BleAdvertisement::SocketVersion::kV1,
service_id_hash,
data,
device_token};
service_id_hash, data, device_token};
EXPECT_TRUE(ble_advertisement.IsValid());
EXPECT_FALSE(ble_advertisement.IsFastAdvertisement());
@@ -67,9 +65,7 @@ TEST(BleAdvertisementTest, ConstructionWorksV1ForFastAdvertisement) {
BleAdvertisement ble_advertisement{BleAdvertisement::Version::kV1,
BleAdvertisement::SocketVersion::kV1,
ByteArray{},
fast_data,
device_token};
ByteArray{}, fast_data, device_token};
EXPECT_TRUE(ble_advertisement.IsValid());
EXPECT_TRUE(ble_advertisement.IsFastAdvertisement());
@@ -89,18 +85,12 @@ TEST(BleAdvertisementTest, ConstructionFailsWithBadVersion) {
ByteArray data{std::string(kData)};
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement ble_advertisement{bad_version,
kSocketVersion,
service_id_hash,
data,
device_token};
BleAdvertisement ble_advertisement{bad_version, kSocketVersion,
service_id_hash, data, device_token};
EXPECT_FALSE(ble_advertisement.IsValid());
BleAdvertisement fast_ble_advertisement{bad_version,
kSocketVersion,
ByteArray{},
data,
device_token};
BleAdvertisement fast_ble_advertisement{bad_version, kSocketVersion,
ByteArray{}, data, device_token};
EXPECT_FALSE(fast_ble_advertisement.IsValid());
}
@@ -112,18 +102,12 @@ TEST(BleAdvertisementTest, ConstructionFailsWithBadSocketVersion) {
ByteArray data{std::string(kData)};
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement ble_advertisement{kVersion,
bad_socket_version,
service_id_hash,
data,
device_token};
BleAdvertisement ble_advertisement{kVersion, bad_socket_version,
service_id_hash, data, device_token};
EXPECT_FALSE(ble_advertisement.IsValid());
BleAdvertisement fast_ble_advertisement{kVersion,
bad_socket_version,
ByteArray{},
data,
device_token};
BleAdvertisement fast_ble_advertisement{kVersion, bad_socket_version,
ByteArray{}, data, device_token};
EXPECT_FALSE(fast_ble_advertisement.IsValid());
}
@@ -134,11 +118,8 @@ TEST(BleAdvertisementTest, ConstructionFailsWithShortServiceIdHash) {
ByteArray data{std::string(kData)};
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement ble_advertisement{kVersion,
kSocketVersion,
bad_service_id_hash,
data,
device_token};
BleAdvertisement ble_advertisement{kVersion, kSocketVersion,
bad_service_id_hash, data, device_token};
EXPECT_FALSE(ble_advertisement.IsValid());
}
@@ -150,11 +131,8 @@ TEST(BleAdvertisementTest, ConstructionFailsWithLongServiceIdHash) {
ByteArray data{std::string(kData)};
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement ble_advertisement{kVersion,
kSocketVersion,
bad_service_id_hash,
data,
device_token};
BleAdvertisement ble_advertisement{kVersion, kSocketVersion,
bad_service_id_hash, data, device_token};
EXPECT_FALSE(ble_advertisement.IsValid());
}
@@ -168,18 +146,12 @@ TEST(BleAdvertisementTest, ConstructionFailsWithLongData) {
ByteArray bad_data{long_data, 512};
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement ble_advertisement{kVersion,
kSocketVersion,
service_id_hash,
bad_data,
device_token};
BleAdvertisement ble_advertisement{kVersion, kSocketVersion, service_id_hash,
bad_data, device_token};
EXPECT_FALSE(ble_advertisement.IsValid());
BleAdvertisement fast_ble_advertisement{kVersion,
kSocketVersion,
ByteArray{},
bad_data,
device_token};
BleAdvertisement fast_ble_advertisement{kVersion, kSocketVersion, ByteArray{},
bad_data, device_token};
EXPECT_FALSE(fast_ble_advertisement.IsValid());
}
@@ -187,11 +159,8 @@ TEST(BleAdvertisementTest, ConstructionWorksWithEmptyDeviceToken) {
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
ByteArray data{std::string(kData)};
BleAdvertisement ble_advertisement{kVersion,
kSocketVersion,
service_id_hash,
data,
ByteArray{}};
BleAdvertisement ble_advertisement{kVersion, kSocketVersion, service_id_hash,
data, ByteArray{}};
EXPECT_TRUE(ble_advertisement.IsValid());
EXPECT_FALSE(ble_advertisement.IsFastAdvertisement());
@@ -207,11 +176,8 @@ TEST(BleAdvertisementTest,
ConstructionWorksWithEmptyDeviceTokenForFastAdvertisement) {
ByteArray fast_data{std::string(kFastData)};
BleAdvertisement ble_advertisement{kVersion,
kSocketVersion,
ByteArray{},
fast_data,
ByteArray{}};
BleAdvertisement ble_advertisement{kVersion, kSocketVersion, ByteArray{},
fast_data, ByteArray{}};
EXPECT_TRUE(ble_advertisement.IsValid());
EXPECT_TRUE(ble_advertisement.IsFastAdvertisement());
@@ -231,32 +197,20 @@ TEST(BleAdvertisementTest, ConstructionFailsWithWrongSizeofDeviceToken) {
ByteArray bad_device_token_1{wrong_device_token_bytes_1};
ByteArray bad_device_token_2{wrong_device_token_bytes_2};
BleAdvertisement ble_advertisement_1{kVersion,
kSocketVersion,
service_id_hash,
data,
bad_device_token_1};
BleAdvertisement ble_advertisement_1{
kVersion, kSocketVersion, service_id_hash, data, bad_device_token_1};
EXPECT_FALSE(ble_advertisement_1.IsValid());
BleAdvertisement ble_advertisement_2{kVersion,
kSocketVersion,
service_id_hash,
data,
bad_device_token_2};
BleAdvertisement ble_advertisement_2{
kVersion, kSocketVersion, service_id_hash, data, bad_device_token_2};
EXPECT_FALSE(ble_advertisement_2.IsValid());
BleAdvertisement fast_ble_advertisement_1{kVersion,
kSocketVersion,
ByteArray{},
data,
bad_device_token_1};
BleAdvertisement fast_ble_advertisement_1{
kVersion, kSocketVersion, ByteArray{}, data, bad_device_token_1};
EXPECT_FALSE(fast_ble_advertisement_1.IsValid());
BleAdvertisement fast_ble_advertisement_2{kVersion,
kSocketVersion,
ByteArray{},
data,
bad_device_token_2};
BleAdvertisement fast_ble_advertisement_2{
kVersion, kSocketVersion, ByteArray{}, data, bad_device_token_2};
EXPECT_FALSE(fast_ble_advertisement_2.IsValid());
}
@@ -265,11 +219,8 @@ TEST(BleAdvertisementTest, ConstructionFromSerializedBytesWorks) {
ByteArray data{std::string(kData)};
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement org_ble_advertisement{kVersion,
kSocketVersion,
service_id_hash,
data,
device_token};
BleAdvertisement org_ble_advertisement{kVersion, kSocketVersion,
service_id_hash, data, device_token};
ByteArray ble_advertisement_bytes{org_ble_advertisement};
BleAdvertisement ble_advertisement{ble_advertisement_bytes};
@@ -289,11 +240,8 @@ TEST(BleAdvertisementTest,
ByteArray fast_data{std::string(kFastData)};
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement org_ble_advertisement{kVersion,
kSocketVersion,
ByteArray{},
fast_data,
device_token};
BleAdvertisement org_ble_advertisement{kVersion, kSocketVersion, ByteArray{},
fast_data, device_token};
ByteArray ble_advertisement_bytes{org_ble_advertisement};
BleAdvertisement ble_advertisement{ble_advertisement_bytes};
@@ -311,11 +259,8 @@ TEST(BleAdvertisementTest, ConstructionFromSerializedBytesWithEmptyDataWorks) {
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement org_ble_advertisement{kVersion,
kSocketVersion,
service_id_hash,
ByteArray(),
device_token};
BleAdvertisement org_ble_advertisement{
kVersion, kSocketVersion, service_id_hash, ByteArray(), device_token};
ByteArray ble_advertisement_bytes{org_ble_advertisement};
BleAdvertisement ble_advertisement{ble_advertisement_bytes};
@@ -332,11 +277,8 @@ TEST(BleAdvertisementTest,
ConstructionFromSerializedBytesWithEmptyDataWorksForFastAdvertisement) {
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement org_ble_advertisement{kVersion,
kSocketVersion,
ByteArray{},
ByteArray(),
device_token};
BleAdvertisement org_ble_advertisement{kVersion, kSocketVersion, ByteArray{},
ByteArray(), device_token};
ByteArray ble_advertisement_bytes{org_ble_advertisement};
BleAdvertisement ble_advertisement{ble_advertisement_bytes};
@@ -353,11 +295,8 @@ TEST(BleAdvertisementTest, ConstructionFromExtraSerializedBytesWorks) {
ByteArray data{std::string(kData)};
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement org_ble_advertisement{kVersion,
kSocketVersion,
service_id_hash,
data,
device_token};
BleAdvertisement org_ble_advertisement{kVersion, kSocketVersion,
service_id_hash, data, device_token};
ByteArray org_ble_advertisement_bytes{org_ble_advertisement};
// Copy the bytes into a new array with extra bytes. We must explicitly
@@ -387,11 +326,8 @@ TEST(BleAdvertisementTest,
ByteArray fast_data{std::string(kFastData)};
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement org_ble_advertisement{kVersion,
kSocketVersion,
ByteArray{},
fast_data,
device_token};
BleAdvertisement org_ble_advertisement{kVersion, kSocketVersion, ByteArray{},
fast_data, device_token};
ByteArray org_ble_advertisement_bytes{org_ble_advertisement};
// Copy the bytes into a new array with extra bytes. We must explicitly
@@ -426,11 +362,8 @@ TEST(BleAdvertisementTest, ConstructionFromShortLengthSerializedBytesFails) {
ByteArray data{std::string(kData)};
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement org_ble_advertisement{kVersion,
kSocketVersion,
service_id_hash,
data,
device_token};
BleAdvertisement org_ble_advertisement{kVersion, kSocketVersion,
service_id_hash, data, device_token};
ByteArray org_ble_advertisement_bytes{org_ble_advertisement};
// Cut off the advertisement so that it's too short.
@@ -446,11 +379,8 @@ TEST(BleAdvertisementTest,
ByteArray fast_data{std::string(kFastData)};
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement org_ble_advertisement{kVersion,
kSocketVersion,
ByteArray{},
fast_data,
device_token};
BleAdvertisement org_ble_advertisement{kVersion, kSocketVersion, ByteArray{},
fast_data, device_token};
ByteArray org_ble_advertisement_bytes{org_ble_advertisement};
// Cut off the advertisement so that it's too short.
@@ -467,11 +397,8 @@ TEST(BleAdvertisementTest,
ByteArray data{std::string(kData)};
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement org_ble_advertisement{kVersion,
kSocketVersion,
service_id_hash,
data,
device_token};
BleAdvertisement org_ble_advertisement{kVersion, kSocketVersion,
service_id_hash, data, device_token};
ByteArray org_ble_advertisement_bytes{org_ble_advertisement};
// Corrupt the DATA_SIZE bits. Start by making a raw copy of the Ble
@@ -498,11 +425,8 @@ TEST(BleAdvertisementTest,
ByteArray fast_data{std::string(kFastData)};
ByteArray device_token{std::string(kDeviceToken)};
BleAdvertisement org_ble_advertisement{kVersion,
kSocketVersion,
ByteArray{},
fast_data,
device_token};
BleAdvertisement org_ble_advertisement{kVersion, kSocketVersion, ByteArray{},
fast_data, device_token};
ByteArray org_ble_advertisement_bytes{org_ble_advertisement};
// Corrupt the DATA_SIZE bits. Start by making a raw copy of the Ble
@@ -14,9 +14,9 @@
#include "core/internal/mediums/ble_v2/ble_packet.h"
#include "absl/strings/str_cat.h"
#include "platform/base/base_input_stream.h"
#include "platform/public/logging.h"
#include "absl/strings/str_cat.h"
namespace location {
namespace nearby {
@@ -18,6 +18,7 @@
#include <cstdint>
#include <string>
#include "absl/container/flat_hash_map.h"
#include "core/internal/mediums/bluetooth_radio.h"
#include "core/listeners.h"
#include "platform/base/byte_array.h"
@@ -26,7 +27,6 @@
#include "platform/public/bluetooth_classic.h"
#include "platform/public/multi_thread_executor.h"
#include "platform/public/mutex.h"
#include "absl/container/flat_hash_map.h"
namespace location {
namespace nearby {
@@ -16,15 +16,15 @@
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
#include "core/internal/mediums/bluetooth_radio.h"
#include "platform/base/medium_environment.h"
#include "platform/public/bluetooth_classic.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/logging.h"
#include "platform/public/system_clock.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
+3 -7
View File
@@ -17,9 +17,9 @@
#include <cstdint>
#include "absl/time/clock.h"
#include "platform/public/atomic_boolean.h"
#include "platform/public/bluetooth_adapter.h"
#include "absl/time/clock.h"
namespace location {
namespace nearby {
@@ -56,13 +56,9 @@ class BluetoothRadio {
bool Toggle();
// Returns result of BluetoothAdapter::IsValid() for private adapter instance.
bool IsAdapterValid() const {
return bluetooth_adapter_.IsValid();
}
bool IsAdapterValid() const { return bluetooth_adapter_.IsValid(); }
BluetoothAdapter& GetBluetoothAdapter() {
return bluetooth_adapter_;
}
BluetoothAdapter& GetBluetoothAdapter() { return bluetooth_adapter_; }
private:
static constexpr absl::Duration kPauseBetweenToggle = absl::Seconds(3);
@@ -15,9 +15,9 @@
#ifndef CORE_INTERNAL_MEDIUMS_LOST_ENTITY_TRACKER_H_
#define CORE_INTERNAL_MEDIUMS_LOST_ENTITY_TRACKER_H_
#include "absl/container/flat_hash_set.h"
#include "platform/public/mutex.h"
#include "platform/public/mutex_lock.h"
#include "absl/container/flat_hash_set.h"
namespace location {
namespace nearby {
+3 -9
View File
@@ -18,19 +18,13 @@ namespace location {
namespace nearby {
namespace connections {
BluetoothRadio& Mediums::GetBluetoothRadio() {
return bluetooth_radio_;
}
BluetoothRadio& Mediums::GetBluetoothRadio() { return bluetooth_radio_; }
BluetoothClassic& Mediums::GetBluetoothClassic() {
return bluetooth_classic_;
}
BluetoothClassic& Mediums::GetBluetoothClassic() { return bluetooth_classic_; }
Ble& Mediums::GetBle() { return ble_; }
WifiLan& Mediums::GetWifiLan() {
return wifi_lan_;
}
WifiLan& Mediums::GetWifiLan() { return wifi_lan_; }
mediums::WebRtc& Mediums::GetWebRtc() { return webrtc_; }
+2 -4
View File
@@ -25,10 +25,8 @@ namespace connections {
namespace {
std::ostream& write_hex(std::ostream& os, absl::string_view data) {
for (const auto b : data) {
os << std::setfill('0')
<< std::setw(2)
<< std::hex
<< (static_cast<unsigned int>(b) & 0x0ff);
os << std::setfill('0') << std::setw(2) << std::hex
<< (static_cast<unsigned int>(b) & 0x0ff);
}
return os;
}
+1 -3
View File
@@ -44,9 +44,7 @@ class Uuid final {
// (https://en.wikipedia.org/wiki/Universally_unique_identifier#Format) of the
// UUID.
explicit operator std::string() const;
std::string data() const {
return data_;
}
std::string data() const { return data_; }
private:
std::string data_;
+6 -6
View File
@@ -14,10 +14,10 @@
#include "core/internal/mediums/uuid.h"
#include "platform/public/crypto.h"
#include "platform/public/logging.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "platform/public/crypto.h"
#include "platform/public/logging.h"
namespace location {
namespace nearby {
@@ -52,16 +52,16 @@ TEST(UuidTest, CreateFromBinary) {
EXPECT_EQ(uuid_data[3], (kNum1 >> 32) & 0xFF);
EXPECT_EQ(uuid_data[4], (kNum1 >> 24) & 0xFF);
EXPECT_EQ(uuid_data[5], (kNum1 >> 16) & 0xFF);
EXPECT_EQ(uuid_data[6], (kNum1 >> 8) & 0xFF);
EXPECT_EQ(uuid_data[7], (kNum1 >> 0) & 0xFF);
EXPECT_EQ(uuid_data[6], (kNum1 >> 8) & 0xFF);
EXPECT_EQ(uuid_data[7], (kNum1 >> 0) & 0xFF);
EXPECT_EQ(uuid_data[8], (kNum2 >> 56) & 0xFF);
EXPECT_EQ(uuid_data[9], (kNum2 >> 48) & 0xFF);
EXPECT_EQ(uuid_data[10], (kNum2 >> 40) & 0xFF);
EXPECT_EQ(uuid_data[11], (kNum2 >> 32) & 0xFF);
EXPECT_EQ(uuid_data[12], (kNum2 >> 24) & 0xFF);
EXPECT_EQ(uuid_data[13], (kNum2 >> 16) & 0xFF);
EXPECT_EQ(uuid_data[14], (kNum2 >> 8) & 0xFF);
EXPECT_EQ(uuid_data[15], (kNum2 >> 0) & 0xFF);
EXPECT_EQ(uuid_data[14], (kNum2 >> 8) & 0xFF);
EXPECT_EQ(uuid_data[15], (kNum2 >> 0) & 0xFF);
}
} // namespace
+4 -4
View File
@@ -17,6 +17,10 @@
#include <functional>
#include <memory>
#include "location/nearby/mediums/proto/web_rtc_signaling_frames.pb.h"
#include "absl/functional/bind_front.h"
#include "absl/strings/str_cat.h"
#include "absl/time/time.h"
#include "core/internal/mediums/webrtc/session_description_wrapper.h"
#include "core/internal/mediums/webrtc/signaling_frames.h"
#include "core/internal/mediums/webrtc/webrtc_socket_wrapper.h"
@@ -26,10 +30,6 @@
#include "platform/public/future.h"
#include "platform/public/logging.h"
#include "platform/public/mutex_lock.h"
#include "location/nearby/mediums/proto/web_rtc_signaling_frames.pb.h"
#include "absl/functional/bind_front.h"
#include "absl/strings/str_cat.h"
#include "absl/time/time.h"
#include "webrtc/api/jsep.h"
namespace location {
+4 -4
View File
@@ -20,13 +20,16 @@
#include <memory>
#include <string>
#include "proto/connections/offline_wire_formats.pb.h"
#include "location/nearby/mediums/proto/web_rtc_signaling_frames.pb.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "core/internal/mediums/webrtc/connection_flow.h"
#include "core/internal/mediums/webrtc/data_channel_listener.h"
#include "core/internal/mediums/webrtc/local_ice_candidate_listener.h"
#include "core/internal/mediums/webrtc/peer_id.h"
#include "core/internal/mediums/webrtc/webrtc_socket.h"
#include "core/internal/mediums/webrtc/webrtc_socket_wrapper.h"
#include "proto/connections/offline_wire_formats.pb.h"
#include "platform/base/byte_array.h"
#include "platform/base/cancellation_flag.h"
#include "platform/base/listeners.h"
@@ -38,9 +41,6 @@
#include "platform/public/scheduled_executor.h"
#include "platform/public/single_thread_executor.h"
#include "platform/public/webrtc.h"
#include "location/nearby/mediums/proto/web_rtc_signaling_frames.pb.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "webrtc/api/data_channel_interface.h"
#include "webrtc/api/jsep.h"
#include "webrtc/api/scoped_refptr.h"
+9 -8
View File
@@ -1,3 +1,4 @@
licenses(["notice"])
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,18 +35,18 @@ cc_library(
"//core/internal:__subpackages__",
],
deps = [
"//location/nearby/mediums/proto:web_rtc_signaling_frames_cc_proto",
"//absl/memory",
"//absl/strings",
"//absl/time",
"//core:core_types",
"//core/internal/mediums:utils",
"//platform/base",
"//platform/public:comm",
"//platform/public:logging",
"//platform/public:types",
"//location/nearby/mediums/proto:web_rtc_signaling_frames_cc_proto",
"//absl/memory",
"//absl/strings",
"//absl/time",
"//webrtc/api:libjingle_peerconnection_api",
"//webrtc/pc:peerconnection",
"//third_party/webrtc/files/stable/webrtc/pc:peerconnection",
],
)
@@ -61,14 +62,14 @@ cc_test(
tags = ["notsan"], # NOTE(b/139734036): known data race in usrsctplib.
deps = [
":webrtc",
"//net/proto2/compat/public:proto2",
"//testing/base/public:gunit_main",
"//absl/time",
"//platform/base",
"//platform/base:test_util",
"//platform/impl/g3", # buildcleaner: keep
"//platform/public:comm",
"//platform/public:types",
"//net/proto2/public:proto2",
"//testing/base/public:gunit_main",
"//absl/time",
"//webrtc/api:libjingle_peerconnection_api",
"//webrtc/api:rtc_error",
"//webrtc/api:scoped_refptr",
@@ -17,14 +17,14 @@
#include <iterator>
#include <memory>
#include "absl/memory/memory.h"
#include "absl/time/time.h"
#include "core/internal/mediums/webrtc/session_description_wrapper.h"
#include "core/internal/mediums/webrtc/webrtc_socket.h"
#include "core/internal/mediums/webrtc/webrtc_socket_wrapper.h"
#include "platform/public/logging.h"
#include "platform/public/mutex_lock.h"
#include "platform/public/webrtc.h"
#include "absl/memory/memory.h"
#include "absl/time/time.h"
#include "webrtc/api/data_channel_interface.h"
#include "webrtc/api/jsep.h"
@@ -522,8 +522,7 @@ bool ConnectionFlow::RunOnSignalingThread(Runnable&& runnable) {
// (signaling thread). This guarantees that if the weak_ptr is valid
// when this task starts, it will stay valid until the task ends.
if (!can_run_tasks.lock()) {
NEARBY_LOG(INFO,
"Peer connection already closed. Cannot run tasks.");
NEARBY_LOG(INFO, "Peer connection already closed. Cannot run tasks.");
return;
}
task();
@@ -17,15 +17,15 @@
#include <memory>
#include <vector>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
#include "core/internal/mediums/webrtc/session_description_wrapper.h"
#include "core/internal/mediums/webrtc/webrtc_socket_wrapper.h"
#include "platform/base/byte_array.h"
#include "platform/base/medium_environment.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/webrtc.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
#include "webrtc/api/data_channel_interface.h"
#include "webrtc/api/jsep.h"
#include "webrtc/api/rtc_error.h"
+1 -1
View File
@@ -16,9 +16,9 @@
#include <sstream>
#include "core/internal/mediums/utils.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "core/internal/mediums/utils.h"
namespace location {
namespace nearby {
@@ -16,10 +16,10 @@
#include <memory>
#include "platform/base/byte_array.h"
#include "platform/public/crypto.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "platform/base/byte_array.h"
#include "platform/public/crypto.h"
namespace location {
namespace nearby {
@@ -17,9 +17,9 @@
#include <vector>
#include "location/nearby/mediums/proto/web_rtc_signaling_frames.pb.h"
#include "core/internal/mediums/webrtc/peer_id.h"
#include "platform/base/byte_array.h"
#include "location/nearby/mediums/proto/web_rtc_signaling_frames.pb.h"
#include "webrtc/api/peer_connection_interface.h"
namespace location {
@@ -16,10 +16,10 @@
#include <memory>
#include "core/internal/mediums/webrtc/peer_id.h"
#include "net/proto2/public/text_format.h"
#include "google/protobuf/text_format.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "core/internal/mediums/webrtc/peer_id.h"
namespace location {
namespace nearby {
@@ -59,16 +59,16 @@ WebRtcSocket::WebRtcSocket(
rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel)
: name_(name), data_channel_(std::move(data_channel)) {
NEARBY_LOGS(INFO) << "WebRtcSocket::WebRtcSocket(" << name_
<< ") this: " << this;
<< ") this: " << this;
data_channel_->RegisterObserver(this);
}
WebRtcSocket::~WebRtcSocket() {
NEARBY_LOGS(INFO) << "WebRtcSocket::~WebRtcSocket(" << name_
<< ") this: " << this;
<< ") this: " << this;
Close();
NEARBY_LOGS(INFO) << "WebRtcSocket::~WebRtcSocket(" << name_
<< ") this: " << this << " done";
<< ") this: " << this << " done";
}
InputStream& WebRtcSocket::GetInputStream() { return pipe_.GetInputStream(); }
@@ -85,7 +85,7 @@ void WebRtcSocket::Close() {
// is not fully closed when this call is done.
data_channel_->Close();
NEARBY_LOGS(INFO) << "WebRtcSocket::Close(" << name_ << ") this: " << this
<< " done";
<< " done";
}
void WebRtcSocket::OnStateChange() {
@@ -150,15 +150,15 @@ bool WebRtcSocket::IsClosed() { return closed_.Get(); }
void WebRtcSocket::ClosePipe() {
NEARBY_LOGS(INFO) << "WebRtcSocket::ClosePipe(" << name_
<< ") this: " << this;
<< ") this: " << this;
// This is thread-safe to close these sockets even if a read or write is in
// process on another thread, Close will wait for the exclusive mutex before
// setting state.
pipe_.GetInputStream().Close();
pipe_.GetOutputStream().Close();
WakeUpWriter();
NEARBY_LOGS(INFO) << "WebRtcSocket::ClosePipe(" << name_
<< ") this: " << this << " done";
NEARBY_LOGS(INFO) << "WebRtcSocket::ClosePipe(" << name_ << ") this: " << this
<< " done";
}
// Must not be called on signalling thread.
@@ -16,9 +16,9 @@
#include <memory>
#include "platform/base/byte_array.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "platform/base/byte_array.h"
#include "webrtc/api/data_channel_interface.h"
namespace location {
+2 -2
View File
@@ -14,12 +14,12 @@
#include "core/internal/mediums/webrtc.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "core/internal/mediums/webrtc/webrtc_socket_wrapper.h"
#include "platform/base/listeners.h"
#include "platform/base/medium_environment.h"
#include "platform/public/mutex_lock.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
namespace location {
namespace nearby {
+2 -2
View File
@@ -18,13 +18,13 @@
#include <cstdint>
#include <string>
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "platform/base/byte_array.h"
#include "platform/base/cancellation_flag.h"
#include "platform/public/multi_thread_executor.h"
#include "platform/public/mutex.h"
#include "platform/public/wifi_lan.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
namespace location {
namespace nearby {
+3 -3
View File
@@ -16,13 +16,13 @@
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
#include "platform/base/medium_environment.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/logging.h"
#include "platform/public/wifi_lan.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
namespace location {
namespace nearby {
+1 -1
View File
@@ -15,8 +15,8 @@
#ifndef CORE_INTERNAL_MOCK_SERVICE_CONTROLLER_H_
#define CORE_INTERNAL_MOCK_SERVICE_CONTROLLER_H_
#include "core/internal/service_controller.h"
#include "gmock/gmock.h"
#include "core/internal/service_controller.h"
namespace location {
namespace nearby {
+3 -6
View File
@@ -64,8 +64,7 @@ V1Frame::FrameType GetFrameType(const OfflineFrame& frame) {
ByteArray ForConnectionRequest(const std::string& endpoint_id,
const ByteArray& endpoint_info,
std::int32_t nonce,
bool supports_5_ghz,
std::int32_t nonce, bool supports_5_ghz,
const std::string& bssid,
const std::vector<Medium>& mediums,
std::int32_t keep_alive_interval_millis,
@@ -76,8 +75,7 @@ ByteArray ForConnectionRequest(const std::string& endpoint_id,
auto* v1_frame = frame.mutable_v1();
v1_frame->set_type(V1Frame::CONNECTION_REQUEST);
auto* connection_request = v1_frame->mutable_connection_request();
if (!endpoint_id.empty())
connection_request->set_endpoint_id(endpoint_id);
if (!endpoint_id.empty()) connection_request->set_endpoint_id(endpoint_id);
if (!endpoint_info.Empty()) {
connection_request->set_endpoint_name(std::string(endpoint_info));
connection_request->set_endpoint_info(std::string(endpoint_info));
@@ -85,8 +83,7 @@ ByteArray ForConnectionRequest(const std::string& endpoint_id,
connection_request->set_nonce(nonce);
auto* medium_metadata = connection_request->mutable_medium_metadata();
medium_metadata->set_supports_5_ghz(supports_5_ghz);
if (!bssid.empty())
medium_metadata->set_bssid(bssid);
if (!bssid.empty()) medium_metadata->set_bssid(bssid);
if (!mediums.empty()) {
for (const auto& medium : mediums) {
connection_request->add_mediums(MediumToConnectionRequestMedium(medium));
+2 -3
View File
@@ -18,8 +18,8 @@
#include <cstdint>
#include <vector>
#include "core/options.h"
#include "proto/connections/offline_wire_formats.pb.h"
#include "core/options.h"
#include "platform/base/byte_array.h"
#include "platform/base/exception.h"
@@ -44,8 +44,7 @@ V1Frame::FrameType GetFrameType(const OfflineFrame& offline_frame);
// Builds Connection Request / Response messages.
ByteArray ForConnectionRequest(const std::string& endpoint_id,
const ByteArray& endpoint_info,
std::int32_t nonce,
bool supports_5_ghz,
std::int32_t nonce, bool supports_5_ghz,
const std::string& bssid,
const std::vector<Medium>& mediums,
std::int32_t keep_alive_interval_millis,
+4 -10
View File
@@ -20,9 +20,9 @@
#include <vector>
#include "proto/connections/offline_wire_formats.pb.h"
#include "platform/base/byte_array.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "platform/base/byte_array.h"
namespace location {
namespace nearby {
@@ -92,10 +92,7 @@ TEST(OfflineFramesTest, CanGenerateConnectionRequest) {
endpoint_name: "XYZ"
endpoint_info: "XYZ"
nonce: 1234
medium_metadata: <
supports_5_ghz: true
bssid: "FF:FF:FF:FF:FF:FF"
>
medium_metadata: < supports_5_ghz: true bssid: "FF:FF:FF:FF:FF:FF" >
mediums: MDNS
mediums: BLUETOOTH
mediums: WIFI_HOTSPOT
@@ -106,7 +103,7 @@ TEST(OfflineFramesTest, CanGenerateConnectionRequest) {
mediums: WIFI_DIRECT
mediums: WEB_RTC
keep_alive_interval_millis: 1000
keep_alive_timeout_millis : 5000
keep_alive_timeout_millis: 5000
>
>)pb";
ByteArray bytes = ForConnectionRequest(
@@ -126,10 +123,7 @@ TEST(OfflineFramesTest, CanGenerateConnectionResponse) {
version: V1
v1: <
type: CONNECTION_RESPONSE
connection_response: <
status: 1
response: REJECT
>
connection_response: < status: 1 response: REJECT >
>)pb";
ByteArray bytes = ForConnectionResponse(1);
auto response = FromBytes(bytes);
@@ -16,9 +16,9 @@
#include <regex> //NOLINT
#include "proto/connections/offline_wire_formats.pb.h"
#include "core/internal/internal_payload.h"
#include "core/internal/offline_frames.h"
#include "proto/connections/offline_wire_formats.pb.h"
namespace location {
namespace nearby {
@@ -16,11 +16,11 @@
#include <string>
#include "core/internal/offline_frames.h"
#include "proto/connections/offline_wire_formats.pb.h"
#include "platform/base/byte_array.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "core/internal/offline_frames.h"
#include "platform/base/byte_array.h"
namespace location {
namespace nearby {
@@ -52,8 +52,7 @@ class OfflineServiceController : public ServiceController {
const DiscoveryListener& listener) override;
void StopDiscovery(ClientProxy* client) override;
void InjectEndpoint(ClientProxy* client,
const std::string& service_id,
void InjectEndpoint(ClientProxy* client, const std::string& service_id,
const OutOfBandConnectionMetadata& metadata) override;
Status RequestConnection(ClientProxy* client, const std::string& endpoint_id,
@@ -16,6 +16,8 @@
#include <array>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "core/internal/offline_simulation_user.h"
#include "platform/base/medium_environment.h"
#include "platform/base/output_stream.h"
@@ -23,8 +25,6 @@
#include "platform/public/logging.h"
#include "platform/public/pipe.h"
#include "platform/public/system_clock.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
namespace location {
namespace nearby {
@@ -373,11 +373,11 @@ TEST_F(OfflineServiceControllerTest, InjectEndpoint) {
Eq(Status{Status::kSuccess}));
EXPECT_TRUE(user_a.IsDiscovering());
user_a.InjectEndpoint(
std::string(kServiceId),
OutOfBandConnectionMetadata{
.medium = Medium::BLUETOOTH,
.remote_bluetooth_mac_address = ByteArray(kFakeMacAddress),
});
std::string(kServiceId),
OutOfBandConnectionMetadata{
.medium = Medium::BLUETOOTH,
.remote_bluetooth_mac_address = ByteArray(kFakeMacAddress),
});
user_a.Stop();
env_.Stop();
}
+7 -8
View File
@@ -14,11 +14,11 @@
#include "core/internal/offline_simulation_user.h"
#include "absl/functional/bind_front.h"
#include "core/listeners.h"
#include "platform/base/byte_array.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/system_clock.h"
#include "absl/functional/bind_front.h"
namespace location {
namespace nearby {
@@ -168,13 +168,12 @@ Status OfflineSimulationUser::RequestConnection(CountDownLatch* latch) {
absl::bind_front(&OfflineSimulationUser::OnEndpointDisconnect, this),
};
client_.AddCancellationFlag(discovered_.endpoint_id);
return ctrl_.RequestConnection(
&client_, discovered_.endpoint_id,
{
.endpoint_info = discovered_.endpoint_info,
.listener = std::move(listener),
},
connection_options_);
return ctrl_.RequestConnection(&client_, discovered_.endpoint_id,
{
.endpoint_info = discovered_.endpoint_info,
.listener = std::move(listener),
},
connection_options_);
}
Status OfflineSimulationUser::AcceptConnection(CountDownLatch* latch) {
+2 -2
View File
@@ -17,6 +17,8 @@
#include <string>
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
#include "core/internal/client_proxy.h"
#include "core/internal/offline_service_controller.h"
#include "core/options.h"
@@ -24,8 +26,6 @@
#include "platform/public/condition_variable.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/future.h"
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
// Test-only class to help run end-to-end simulations for nearby connections
// protocol.
+3 -3
View File
@@ -14,6 +14,9 @@
#include "core/internal/p2p_cluster_pcp_handler.h"
#include "proto/connections_enums.pb.h"
#include "absl/functional/bind_front.h"
#include "absl/strings/escaping.h"
#include "core/internal/base_pcp_handler.h"
#include "core/internal/ble_advertisement.h"
#include "core/internal/ble_endpoint_channel.h"
@@ -26,9 +29,6 @@
#include "platform/base/nsd_service_info.h"
#include "platform/base/types.h"
#include "platform/public/crypto.h"
#include "proto/connections_enums.pb.h"
#include "absl/functional/bind_front.h"
#include "absl/strings/escaping.h"
namespace location {
namespace nearby {
@@ -16,15 +16,15 @@
#include <memory>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
#include "core/internal/bwu_manager.h"
#include "core/internal/injected_bluetooth_device_store.h"
#include "core/options.h"
#include "platform/base/medium_environment.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/logging.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
+2 -2
View File
@@ -25,8 +25,8 @@ P2pStarPcpHandler::P2pStarPcpHandler(
EndpointChannelManager& channel_manager, BwuManager& bwu_manager,
InjectedBluetoothDeviceStore& injected_bluetooth_device_store, Pcp pcp)
: P2pClusterPcpHandler(&mediums, &endpoint_manager, &channel_manager,
&bwu_manager, injected_bluetooth_device_store,
pcp) {}
&bwu_manager, injected_bluetooth_device_store, pcp) {
}
std::vector<proto::connections::Medium>
P2pStarPcpHandler::GetConnectionMediumsByPriority() {
+33 -32
View File
@@ -20,14 +20,14 @@
#include <string>
#include <utility>
#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
#include "absl/time/time.h"
#include "core/internal/internal_payload_factory.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/mutex_lock.h"
#include "platform/public/single_thread_executor.h"
#include "platform/public/system_clock.h"
#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
@@ -375,35 +375,36 @@ void PayloadManager::SendPayload(ClientProxy* client,
Payload::Id payload_id =
CreateOutgoingPayload(std::move(payload), endpoint_ids);
executor->Execute("send-payload", [this, client, endpoint_ids, payload_id,
payload_type, resume_offset]() {
if (shutdown_.Get()) return;
PendingPayload* pending_payload = GetPayload(payload_id);
if (!pending_payload) {
NEARBY_LOGS(INFO)
<< "PayloadManager failed to create InternalPayload for outgoing "
"payload_id="
<< payload_id << ", payload_type=" << ToString(payload_type)
<< ", aborting sendPayload().";
return;
}
auto* internal_payload = pending_payload->GetInternalPayload();
if (!internal_payload) return;
PayloadTransferFrame::PayloadHeader payload_header{
CreatePayloadHeader(*internal_payload, resume_offset)};
bool should_continue = true;
std::int64_t next_chunk_offset = 0;
while (should_continue && !shutdown_.Get()) {
should_continue =
SendPayloadLoop(client, *pending_payload, payload_header,
next_chunk_offset, resume_offset);
}
RunOnStatusUpdateThread("destroy-payload",
[this, payload_id]()
RUN_ON_PAYLOAD_STATUS_UPDATE_THREAD() {
DestroyPendingPayload(payload_id);
});
});
executor->Execute(
"send-payload",
[this, client, endpoint_ids, payload_id, payload_type, resume_offset]() {
if (shutdown_.Get()) return;
PendingPayload* pending_payload = GetPayload(payload_id);
if (!pending_payload) {
NEARBY_LOGS(INFO)
<< "PayloadManager failed to create InternalPayload for outgoing "
"payload_id="
<< payload_id << ", payload_type=" << ToString(payload_type)
<< ", aborting sendPayload().";
return;
}
auto* internal_payload = pending_payload->GetInternalPayload();
if (!internal_payload) return;
PayloadTransferFrame::PayloadHeader payload_header{
CreatePayloadHeader(*internal_payload, resume_offset)};
bool should_continue = true;
std::int64_t next_chunk_offset = 0;
while (should_continue && !shutdown_.Get()) {
should_continue =
SendPayloadLoop(client, *pending_payload, payload_header,
next_chunk_offset, resume_offset);
}
RunOnStatusUpdateThread("destroy-payload",
[this, payload_id]()
RUN_ON_PAYLOAD_STATUS_UPDATE_THREAD() {
DestroyPendingPayload(payload_id);
});
});
NEARBY_LOGS(INFO) << "PayloadManager: xfer scheduled: self=" << this
<< "; payload_id=" << payload_id
<< ", payload_type=" << ToString(payload_type);
+2 -2
View File
@@ -20,6 +20,7 @@
#include <string>
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "core/internal/client_proxy.h"
#include "core/internal/endpoint_manager.h"
#include "core/internal/internal_payload.h"
@@ -31,7 +32,6 @@
#include "platform/public/atomic_reference.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/mutex.h"
#include "absl/container/flat_hash_map.h"
namespace location {
namespace nearby {
@@ -85,7 +85,7 @@ class PayloadManager : public EndpointManager::FrameProcessor {
PayloadTransferFrame::ControlMessage::EventType event);
std::string id;
AtomicReference<Status> status {Status::kUnknown};
AtomicReference<Status> status{Status::kUnknown};
std::int64_t offset = 0;
};
+3 -3
View File
@@ -14,13 +14,13 @@
#include "core/internal/payload_manager.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
#include "core/internal/simulation_user.h"
#include "platform/base/byte_array.h"
#include "platform/public/pipe.h"
#include "platform/public/system_clock.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
namespace location {
namespace nearby {
+2 -3
View File
@@ -17,6 +17,7 @@
#include <string>
#include "absl/container/flat_hash_map.h"
#include "core/internal/base_pcp_handler.h"
#include "core/internal/bwu_manager.h"
#include "core/internal/client_proxy.h"
@@ -29,7 +30,6 @@
#include "core/status.h"
#include "core/strategy.h"
#include "platform/public/atomic_boolean.h"
#include "absl/container/flat_hash_map.h"
namespace location {
namespace nearby {
@@ -59,8 +59,7 @@ class PcpManager {
DiscoveryListener listener);
void StopDiscovery(ClientProxy* client);
void InjectEndpoint(ClientProxy* client,
const std::string& service_id,
void InjectEndpoint(ClientProxy* client, const std::string& service_id,
const OutOfBandConnectionMetadata& metadata);
Status RequestConnection(ClientProxy* client, const string& endpoint_id,
+9 -11
View File
@@ -17,14 +17,14 @@
#include <array>
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
#include "core/internal/endpoint_channel_manager.h"
#include "core/internal/simulation_user.h"
#include "core/options.h"
#include "platform/base/medium_environment.h"
#include "platform/public/count_down_latch.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
namespace location {
namespace nearby {
@@ -160,15 +160,13 @@ INSTANTIATE_TEST_SUITE_P(ParametrisedPcpManagerTest, PcpManagerTest,
// Note: Not parameterized because InjectEndpoint only works over Bluetooth.
TEST_F(PcpManagerTest, InjectEndpoint) {
env_.Start();
SimulationUser user_a(kDeviceA,
BooleanMediumSelector{.bluetooth = true});
SimulationUser user_a(kDeviceA, BooleanMediumSelector{.bluetooth = true});
user_a.StartDiscovery(kServiceId, /*latch=*/nullptr);
user_a.InjectEndpoint(
kServiceId,
OutOfBandConnectionMetadata{
.medium = Medium::BLUETOOTH,
.remote_bluetooth_mac_address = ByteArray(kFakeMacAddress),
});
user_a.InjectEndpoint(kServiceId, OutOfBandConnectionMetadata{
.medium = Medium::BLUETOOTH,
.remote_bluetooth_mac_address =
ByteArray(kFakeMacAddress),
});
user_a.Stop();
env_.Stop();
}
@@ -19,6 +19,8 @@
#include <string>
#include <utility>
#include "absl/memory/memory.h"
#include "absl/time/clock.h"
#include "core/internal/client_proxy.h"
#include "core/listeners.h"
#include "core/options.h"
@@ -26,8 +28,6 @@
#include "core/payload.h"
#include "platform/base/feature_flags.h"
#include "platform/public/logging.h"
#include "absl/memory/memory.h"
#include "absl/time/clock.h"
namespace location {
namespace nearby {
@@ -19,15 +19,15 @@
#include <string>
#include <vector>
#include "absl/container/flat_hash_set.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "core/internal/client_proxy.h"
#include "core/internal/service_controller.h"
#include "core/options.h"
#include "core/params.h"
#include "platform/base/runnable.h"
#include "platform/public/single_thread_executor.h"
#include "absl/container/flat_hash_set.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
namespace location {
namespace nearby {
@@ -70,8 +70,7 @@ class ServiceControllerRouter {
const ResultCallback& callback);
void StopDiscovery(ClientProxy* client, const ResultCallback& callback);
void InjectEndpoint(ClientProxy* client,
absl::string_view service_id,
void InjectEndpoint(ClientProxy* client, absl::string_view service_id,
const OutOfBandConnectionMetadata& metadata,
const ResultCallback& callback);
@@ -19,6 +19,11 @@
#include <memory>
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/container/flat_hash_set.h"
#include "absl/time/clock.h"
#include "absl/types/span.h"
#include "core/internal/client_proxy.h"
#include "core/internal/mock_service_controller.h"
#include "core/internal/service_controller.h"
@@ -29,11 +34,6 @@
#include "platform/public/condition_variable.h"
#include "platform/public/mutex.h"
#include "platform/public/mutex_lock.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/container/flat_hash_set.h"
#include "absl/time/clock.h"
#include "absl/types/span.h"
namespace location {
namespace nearby {
+1 -1
View File
@@ -14,10 +14,10 @@
#include "core/internal/simulation_user.h"
#include "absl/functional/bind_front.h"
#include "core/listeners.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/system_clock.h"
#include "absl/functional/bind_front.h"
namespace location {
namespace nearby {
+1 -1
View File
@@ -17,6 +17,7 @@
#include <string>
#include "gtest/gtest.h"
#include "core/internal/bwu_manager.h"
#include "core/internal/client_proxy.h"
#include "core/internal/endpoint_channel_manager.h"
@@ -29,7 +30,6 @@
#include "platform/public/condition_variable.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/future.h"
#include "gtest/gtest.h"
// Test-only class to help run end-to-end simulations for nearby connections
// protocol.
+1 -1
View File
@@ -16,12 +16,12 @@
#include <string>
#include "absl/functional/bind_front.h"
#include "core/internal/client_proxy.h"
#include "core/internal/mediums/utils.h"
#include "core/internal/mediums/webrtc/peer_id.h"
#include "core/internal/offline_frames.h"
#include "core/internal/webrtc_endpoint_channel.h"
#include "absl/functional/bind_front.h"
namespace location {
namespace nearby {
+1 -3
View File
@@ -28,9 +28,7 @@ proto::connections::Medium WebRtcEndpointChannel::GetMedium() const {
return proto::connections::Medium::WEB_RTC;
}
void WebRtcEndpointChannel::CloseImpl() {
webrtc_socket_.Close();
}
void WebRtcEndpointChannel::CloseImpl() { webrtc_socket_.Close(); }
} // namespace connections
} // namespace nearby
+1 -2
View File
@@ -17,12 +17,12 @@
#include <locale>
#include <string>
#include "absl/functional/bind_front.h"
#include "core/internal/client_proxy.h"
#include "core/internal/mediums/utils.h"
#include "core/internal/offline_frames.h"
#include "core/internal/wifi_lan_endpoint_channel.h"
#include "platform/public/wifi_lan.h"
#include "absl/functional/bind_front.h"
namespace location {
namespace nearby {
@@ -154,4 +154,3 @@ void WifiLanBwuHandler::OnIncomingWifiLanConnection(
} // namespace connections
} // namespace nearby
} // namespace location

Some files were not shown because too many files have changed in this diff Show More