From 3c68372b55bc452b64f2135d02d2a8d42ad1b20e Mon Sep 17 00:00:00 2001 From: hai007 Date: Tue, 26 Jan 2021 16:04:52 -0800 Subject: [PATCH] Roll forward up to cl/353971958. --- cpp/core/internal/client_proxy.cc | 30 ++++++++++++++++++++++++++---- cpp/core/internal/mediums/ble.cc | 6 ++++++ proto/bootstrap_enums.proto | 1 - proto/magic_pair_enums.proto | 1 - proto/nearby_client_enums.proto | 1 - 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/cpp/core/internal/client_proxy.cc b/cpp/core/internal/client_proxy.cc index 4aa828f0..b5b3a79f 100644 --- a/cpp/core/internal/client_proxy.cc +++ b/cpp/core/internal/client_proxy.cc @@ -139,15 +139,21 @@ void ClientProxy::OnEndpointFound(const std::string& service_id, endpoint_id.c_str(), service_id.c_str(), absl::BytesToHexString(endpoint_info.data()).c_str()); if (!IsDiscoveringServiceId(service_id)) { - NEARBY_LOG(INFO, "ClientProxy [Endpoint Found]: [no discovery] id=%s", + NEARBY_LOG(INFO, + "ClientProxy [Endpoint Found]: Ignoring event for id=%s because " + "this client is not discovering", endpoint_id.c_str()); return; } + if (discovered_endpoint_ids_.count(endpoint_id)) { - NEARBY_LOG(INFO, "ClientProxy [Endpoint Found]: [duplicate] id=%s", + NEARBY_LOG(WARNING, + "ClientProxy [Endpoint Found]: Ignoring event for id=%s because " + "this client already reported this endpoint as found", endpoint_id.c_str()); return; } + discovered_endpoint_ids_.insert(endpoint_id); discovery_info_.listener.endpoint_found_cb(endpoint_id, endpoint_info, service_id); @@ -157,9 +163,25 @@ void ClientProxy::OnEndpointLost(const std::string& service_id, const std::string& endpoint_id) { MutexLock lock(&mutex_); - if (!IsDiscoveringServiceId(service_id)) return; + NEARBY_LOG(INFO, "ClientProxy [Endpoint Lost]: [enter] id=%s; service=%s", + endpoint_id.c_str(), service_id.c_str()); + if (!IsDiscoveringServiceId(service_id)) { + NEARBY_LOG(INFO, + "ClientProxy [Endpoint Lost]: Ignoring event for id=%s because " + "this client is not discovering", + endpoint_id.c_str()); + return; + } + const auto it = discovered_endpoint_ids_.find(endpoint_id); - if (it == discovered_endpoint_ids_.end()) return; + if (it == discovered_endpoint_ids_.end()) { + NEARBY_LOG(WARNING, + "ClientProxy [Endpoint Lost]: Ignoring event for id=%s because " + "this client has not yet reported this endpoint as found", + endpoint_id.c_str()); + return; + } + discovered_endpoint_ids_.erase(it); discovery_info_.listener.endpoint_lost_cb(endpoint_id); } diff --git a/cpp/core/internal/mediums/ble.cc b/cpp/core/internal/mediums/ble.cc index 2a850b4b..d7d7020b 100644 --- a/cpp/core/internal/mediums/ble.cc +++ b/cpp/core/internal/mediums/ble.cc @@ -172,6 +172,12 @@ bool Ble::StartScanning(const std::string& service_id, const std::string& service_id, const ByteArray& medium_advertisement_bytes, bool fast_advertisement) { + // Don't bother trying to parse zero byte advertisements. + if (medium_advertisement_bytes.size() == 0) { + NEARBY_LOGS(INFO) << "Skipping zero byte advertisement " + << "with service_id: " << service_id; + return; + } // Unwrap connection BleAdvertisement from medium // BleAdvertisement. auto connection_advertisement_bytes = diff --git a/proto/bootstrap_enums.proto b/proto/bootstrap_enums.proto index 1caf01d9..a36fd12f 100644 --- a/proto/bootstrap_enums.proto +++ b/proto/bootstrap_enums.proto @@ -5,7 +5,6 @@ package location.nearby.proto; import "logs/proto/logs_annotations/logs_annotations.proto"; option optimize_for = LITE_RUNTIME; -option jspb_use_correct_proto2_semantics = false; // go/jspb-correct-proto2 option (logs_proto.file_not_used_for_logging_except_enums) = true; option java_api_version = 2; option java_package = "com.google.location.nearby.proto"; diff --git a/proto/magic_pair_enums.proto b/proto/magic_pair_enums.proto index 5269b8cb..8cd616ec 100644 --- a/proto/magic_pair_enums.proto +++ b/proto/magic_pair_enums.proto @@ -5,7 +5,6 @@ package location.nearby.proto; import "logs/proto/logs_annotations/logs_annotations.proto"; option optimize_for = LITE_RUNTIME; -option jspb_use_correct_proto2_semantics = false; // go/jspb-correct-proto2 option (logs_proto.file_not_used_for_logging_except_enums) = true; option java_api_version = 2; option java_package = "com.google.location.nearby.proto"; diff --git a/proto/nearby_client_enums.proto b/proto/nearby_client_enums.proto index 093ef17b..90c01688 100644 --- a/proto/nearby_client_enums.proto +++ b/proto/nearby_client_enums.proto @@ -5,7 +5,6 @@ package location.nearby.proto; import "logs/proto/logs_annotations/logs_annotations.proto"; option optimize_for = LITE_RUNTIME; -option jspb_use_correct_proto2_semantics = false; // go/jspb-correct-proto2 option (logs_proto.file_not_used_for_logging_except_enums) = true; option java_api_version = 2; option java_package = "com.google.location.nearby.proto";