mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Add ConnectionAttemptMetadata for ConnectionAttempt in AnalyticsRecorder.
PiperOrigin-RevId: 413682624
This commit is contained in:
committed by
Copybara-Service
parent
28ed3c75a4
commit
b48610144b
@@ -20,6 +20,7 @@ cc_library(
|
||||
],
|
||||
hdrs = [
|
||||
"analytics_recorder.h",
|
||||
"connection_attempt_metadata_params.h",
|
||||
],
|
||||
compatible_with = ["//buildenv/target:non_prod"],
|
||||
copts = ["-DCORE_ADAPTER_DLL"],
|
||||
|
||||
@@ -43,12 +43,14 @@ using ::location::nearby::proto::connections::CONNECTION_CLOSED;
|
||||
using ::location::nearby::proto::connections::ConnectionAttemptDirection;
|
||||
using ::location::nearby::proto::connections::ConnectionAttemptResult;
|
||||
using ::location::nearby::proto::connections::ConnectionAttemptType;
|
||||
using ::location::nearby::proto::connections::ConnectionBand;
|
||||
using ::location::nearby::proto::connections::ConnectionRequestResponse;
|
||||
using ::location::nearby::proto::connections::ConnectionsStrategy;
|
||||
using ::location::nearby::proto::connections::ConnectionTechnology;
|
||||
using ::location::nearby::proto::connections::DisconnectionReason;
|
||||
using ::location::nearby::proto::connections::DISCOVERER;
|
||||
using ::location::nearby::proto::connections::EventType;
|
||||
using ::location::nearby::proto::connections::ERROR_CODE;
|
||||
using ::location::nearby::proto::connections::EventType;
|
||||
using ::location::nearby::proto::connections::FILE;
|
||||
using ::location::nearby::proto::connections::IGNORED;
|
||||
using ::location::nearby::proto::connections::INCOMING;
|
||||
@@ -247,7 +249,8 @@ void AnalyticsRecorder::OnLocalEndpointRejected(
|
||||
|
||||
void AnalyticsRecorder::OnIncomingConnectionAttempt(
|
||||
ConnectionAttemptType type, Medium medium, ConnectionAttemptResult result,
|
||||
absl::Duration duration, const std::string &connection_token) {
|
||||
absl::Duration duration, const std::string &connection_token,
|
||||
ConnectionAttemptMetadataParams *connection_attempt_metadata_params) {
|
||||
MutexLock lock(&mutex_);
|
||||
if (!CanRecordAnalyticsLocked("OnIncomingConnectionAttempt")) {
|
||||
return;
|
||||
@@ -265,12 +268,44 @@ void AnalyticsRecorder::OnIncomingConnectionAttempt(
|
||||
connection_attempt->set_medium(medium);
|
||||
connection_attempt->set_attempt_result(result);
|
||||
connection_attempt->set_connection_token(connection_token);
|
||||
|
||||
ConnectionAttemptMetadataParams default_params = {};
|
||||
if (connection_attempt_metadata_params == nullptr) {
|
||||
connection_attempt_metadata_params = &default_params;
|
||||
}
|
||||
auto *connection_attempt_metadata =
|
||||
connection_attempt->mutable_connection_attempt_metadata();
|
||||
connection_attempt_metadata->set_technology(
|
||||
connection_attempt_metadata_params->technology);
|
||||
connection_attempt_metadata->set_band(
|
||||
connection_attempt_metadata_params->band);
|
||||
connection_attempt_metadata->set_frequency(
|
||||
connection_attempt_metadata_params->frequency);
|
||||
connection_attempt_metadata->set_network_operator(
|
||||
connection_attempt_metadata_params->network_operator);
|
||||
connection_attempt_metadata->set_country_code(
|
||||
connection_attempt_metadata_params->country_code);
|
||||
connection_attempt_metadata->set_frequency(
|
||||
connection_attempt_metadata_params->frequency);
|
||||
connection_attempt_metadata->set_is_tdls_used(
|
||||
connection_attempt_metadata_params->is_tdls_used);
|
||||
connection_attempt_metadata->set_wifi_hotspot_status(
|
||||
connection_attempt_metadata_params->wifi_hotspot_enabled);
|
||||
connection_attempt_metadata->set_try_counts(
|
||||
connection_attempt_metadata_params->try_count);
|
||||
connection_attempt_metadata->set_max_tx_speed(
|
||||
connection_attempt_metadata_params->max_wifi_tx_speed);
|
||||
connection_attempt_metadata->set_max_rx_speed(
|
||||
connection_attempt_metadata_params->max_wifi_rx_speed);
|
||||
connection_attempt_metadata->set_wifi_channel_width(
|
||||
connection_attempt_metadata_params->channel_width);
|
||||
}
|
||||
|
||||
void AnalyticsRecorder::OnOutgoingConnectionAttempt(
|
||||
const std::string &remote_endpoint_id, ConnectionAttemptType type,
|
||||
Medium medium, ConnectionAttemptResult result, absl::Duration duration,
|
||||
const std::string &connection_token) {
|
||||
const std::string &connection_token,
|
||||
ConnectionAttemptMetadataParams *connection_attempt_metadata_params) {
|
||||
MutexLock lock(&mutex_);
|
||||
if (!CanRecordAnalyticsLocked("OnOutgoingConnectionAttempt")) {
|
||||
return;
|
||||
@@ -288,6 +323,38 @@ void AnalyticsRecorder::OnOutgoingConnectionAttempt(
|
||||
connection_attempt->set_medium(medium);
|
||||
connection_attempt->set_attempt_result(result);
|
||||
connection_attempt->set_connection_token(connection_token);
|
||||
|
||||
ConnectionAttemptMetadataParams default_params = {};
|
||||
if (connection_attempt_metadata_params == nullptr) {
|
||||
connection_attempt_metadata_params = &default_params;
|
||||
}
|
||||
auto *connection_attempt_metadata =
|
||||
connection_attempt->mutable_connection_attempt_metadata();
|
||||
connection_attempt_metadata->set_technology(
|
||||
connection_attempt_metadata_params->technology);
|
||||
connection_attempt_metadata->set_band(
|
||||
connection_attempt_metadata_params->band);
|
||||
connection_attempt_metadata->set_frequency(
|
||||
connection_attempt_metadata_params->frequency);
|
||||
connection_attempt_metadata->set_network_operator(
|
||||
connection_attempt_metadata_params->network_operator);
|
||||
connection_attempt_metadata->set_country_code(
|
||||
connection_attempt_metadata_params->country_code);
|
||||
connection_attempt_metadata->set_frequency(
|
||||
connection_attempt_metadata_params->frequency);
|
||||
connection_attempt_metadata->set_is_tdls_used(
|
||||
connection_attempt_metadata_params->is_tdls_used);
|
||||
connection_attempt_metadata->set_wifi_hotspot_status(
|
||||
connection_attempt_metadata_params->wifi_hotspot_enabled);
|
||||
connection_attempt_metadata->set_try_counts(
|
||||
connection_attempt_metadata_params->try_count);
|
||||
connection_attempt_metadata->set_max_tx_speed(
|
||||
connection_attempt_metadata_params->max_wifi_tx_speed);
|
||||
connection_attempt_metadata->set_max_rx_speed(
|
||||
connection_attempt_metadata_params->max_wifi_rx_speed);
|
||||
connection_attempt_metadata->set_wifi_channel_width(
|
||||
connection_attempt_metadata_params->channel_width);
|
||||
|
||||
if (type == INITIAL && result != RESULT_SUCCESS) {
|
||||
auto it = outgoing_connection_requests_.find(remote_endpoint_id);
|
||||
if (it != outgoing_connection_requests_.end()) {
|
||||
@@ -480,7 +547,7 @@ void AnalyticsRecorder::OnBandwidthUpgradeSuccess(
|
||||
UPGRADE_SUCCESS);
|
||||
}
|
||||
|
||||
void AnalyticsRecorder::OnErrorCode(const ErrorCodeParams& params) {
|
||||
void AnalyticsRecorder::OnErrorCode(const ErrorCodeParams ¶ms) {
|
||||
MutexLock lock(&mutex_);
|
||||
if (!CanRecordAnalyticsLocked("OnErrorCode")) {
|
||||
return;
|
||||
@@ -556,6 +623,28 @@ void AnalyticsRecorder::LogSession() {
|
||||
session_was_logged_ = true;
|
||||
}
|
||||
|
||||
std::unique_ptr<ConnectionAttemptMetadataParams>
|
||||
AnalyticsRecorder::BuildConnectionAttemptMetadataParams(
|
||||
ConnectionTechnology technology, ConnectionBand band, int frequency,
|
||||
int try_count, const std::string &network_operator,
|
||||
const std::string &country_code, bool is_tdls_used,
|
||||
bool wifi_hotspot_enabled, int max_wifi_tx_speed, int max_wifi_rx_speed,
|
||||
int channel_width) {
|
||||
auto params = absl::make_unique<ConnectionAttemptMetadataParams>();
|
||||
params->technology = technology;
|
||||
params->band = band;
|
||||
params->frequency = frequency;
|
||||
params->try_count = try_count;
|
||||
params->network_operator = network_operator;
|
||||
params->country_code = country_code;
|
||||
params->is_tdls_used = is_tdls_used;
|
||||
params->wifi_hotspot_enabled = wifi_hotspot_enabled;
|
||||
params->max_wifi_tx_speed = max_wifi_tx_speed;
|
||||
params->max_wifi_rx_speed = max_wifi_rx_speed;
|
||||
params->channel_width = channel_width;
|
||||
return params;
|
||||
}
|
||||
|
||||
bool AnalyticsRecorder::CanRecordAnalyticsLocked(
|
||||
const std::string &method_name) {
|
||||
NEARBY_LOGS(VERBOSE) << "AnalyticsRecorder LogEvent " << method_name
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "absl/container/btree_map.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "analytics/connection_attempt_metadata_params.h"
|
||||
#include "core/event_logger.h"
|
||||
#include "core/payload.h"
|
||||
#include "core/strategy.h"
|
||||
@@ -72,15 +73,28 @@ class AnalyticsRecorder {
|
||||
location::nearby::proto::connections::ConnectionAttemptType type,
|
||||
location::nearby::proto::connections::Medium medium,
|
||||
location::nearby::proto::connections::ConnectionAttemptResult result,
|
||||
absl::Duration duration, const std::string &connection_token)
|
||||
absl::Duration duration, const std::string &connection_token,
|
||||
ConnectionAttemptMetadataParams *connection_attempt_metadata_params)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
void OnOutgoingConnectionAttempt(
|
||||
const std::string &remote_endpoint_id,
|
||||
location::nearby::proto::connections::ConnectionAttemptType type,
|
||||
location::nearby::proto::connections::Medium medium,
|
||||
location::nearby::proto::connections::ConnectionAttemptResult result,
|
||||
absl::Duration duration, const std::string &connection_token)
|
||||
absl::Duration duration, const std::string &connection_token,
|
||||
ConnectionAttemptMetadataParams *connection_attempt_metadata_params)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
// TODO(edwinwu): Implement network operator, country code, tdls, wifi hotspot
|
||||
//, max wifi tx/rx speed and channel width. Set as default values for
|
||||
// analytics recorder.
|
||||
static std::unique_ptr<ConnectionAttemptMetadataParams>
|
||||
BuildConnectionAttemptMetadataParams(
|
||||
location::nearby::proto::connections::ConnectionTechnology technology,
|
||||
location::nearby::proto::connections::ConnectionBand band, int frequency,
|
||||
int try_count, const std::string &network_operator = {},
|
||||
const std::string &country_code = {}, bool is_tdls_used = false,
|
||||
bool wifi_hotspot_enabled = false, int max_wifi_tx_speed = 0,
|
||||
int max_wifi_rx_speed = 0, int channel_width = -1);
|
||||
|
||||
// Connection established
|
||||
void OnConnectionEstablished(
|
||||
|
||||
@@ -20,12 +20,14 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "analytics/connection_attempt_metadata_params.h"
|
||||
#include "platform/base/error_code_params.h"
|
||||
#include "platform/base/error_code_recorder.h"
|
||||
#include "platform/public/count_down_latch.h"
|
||||
#include "platform/public/logging.h"
|
||||
#include "proto/analytics/connections_log.pb.h"
|
||||
#include "proto/connections_enums.pb.h"
|
||||
#include "proto/connections_enums.proto.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
@@ -453,7 +455,8 @@ TEST(AnalyticsRecorderTest, SuccessfulIncomingConnectionAttempt) {
|
||||
|
||||
analytics_recorder.OnStartAdvertising(strategy, mediums);
|
||||
analytics_recorder.OnIncomingConnectionAttempt(
|
||||
INITIAL, BLUETOOTH, RESULT_SUCCESS, absl::Duration{}, connection_token);
|
||||
INITIAL, BLUETOOTH, RESULT_SUCCESS, absl::Duration{}, connection_token,
|
||||
nullptr);
|
||||
analytics_recorder.OnStopAdvertising();
|
||||
|
||||
analytics_recorder.LogSession();
|
||||
@@ -470,6 +473,19 @@ TEST(AnalyticsRecorderTest, SuccessfulIncomingConnectionAttempt) {
|
||||
medium: BLUETOOTH
|
||||
attempt_result: RESULT_SUCCESS
|
||||
connection_token: ""
|
||||
connection_attempt_metadata <
|
||||
technology: CONNECTION_TECHNOLOGY_UNKNOWN_TECHNOLOGY
|
||||
band: CONNECTION_BAND_UNKNOWN_BAND
|
||||
frequency: -1
|
||||
network_operator: ""
|
||||
country_code: ""
|
||||
is_tdls_used: false
|
||||
try_counts: 0
|
||||
wifi_hotspot_status: false
|
||||
max_tx_speed: 0
|
||||
max_rx_speed: 0
|
||||
wifi_channel_width: -1
|
||||
>
|
||||
>
|
||||
>)pb")));
|
||||
}
|
||||
@@ -485,11 +501,21 @@ TEST(AnalyticsRecorderTest,
|
||||
FakeEventLogger event_logger(client_session_done_latch);
|
||||
AnalyticsRecorder analytics_recorder(&event_logger);
|
||||
|
||||
auto connections_attempt_metadata_params =
|
||||
analytics_recorder.BuildConnectionAttemptMetadataParams(
|
||||
::location::nearby::proto::connections::
|
||||
CONNECTION_TECHNOLOGY_HOTSPOT_LOCALONLY,
|
||||
::location::nearby::proto::connections::
|
||||
CONNECTION_BAND_WIFI_BAND_6GHZ,
|
||||
/*frequency*/ 2400, /*try_count*/ 0, /*network_operator*/ {},
|
||||
/*country_code*/ {}, /*is_tdls_used*/ false,
|
||||
/*wifi_hotspot_enabled*/ false, /*max_wifi_tx_speed*/ 0,
|
||||
/*max_wifi_rx_speed*/ 0, /*channel_width*/ 0);
|
||||
analytics_recorder.OnStartDiscovery(strategy, mediums);
|
||||
analytics_recorder.OnConnectionRequestSent(endpoint_id);
|
||||
analytics_recorder.OnOutgoingConnectionAttempt(
|
||||
endpoint_id, INITIAL, BLUETOOTH, RESULT_ERROR, absl::Duration{},
|
||||
connection_token);
|
||||
connection_token, connections_attempt_metadata_params.get());
|
||||
|
||||
analytics_recorder.LogSession();
|
||||
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
|
||||
@@ -512,6 +538,19 @@ TEST(AnalyticsRecorderTest,
|
||||
medium: BLUETOOTH
|
||||
attempt_result: RESULT_ERROR
|
||||
connection_token: ""
|
||||
connection_attempt_metadata <
|
||||
technology: CONNECTION_TECHNOLOGY_HOTSPOT_LOCALONLY
|
||||
band: CONNECTION_BAND_WIFI_BAND_6GHZ
|
||||
frequency: 2400
|
||||
network_operator: ""
|
||||
country_code: ""
|
||||
is_tdls_used: false
|
||||
try_counts: 0
|
||||
wifi_hotspot_status: false
|
||||
max_tx_speed: 0
|
||||
max_rx_speed: 0
|
||||
wifi_channel_width: 0
|
||||
>
|
||||
>
|
||||
>)pb")));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef ANALYTICS_CONNECTION_ATTEMPT_METADATA_PARAMS_H_
|
||||
#define ANALYTICS_CONNECTION_ATTEMPT_METADATA_PARAMS_H_
|
||||
|
||||
#include "proto/connections_enums.pb.h"
|
||||
#include "proto/connections_enums.proto.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
// A struct to construct ConnectionAttemptMetadata for the analytics recorder.
|
||||
struct ConnectionAttemptMetadataParams {
|
||||
location::nearby::proto::connections::ConnectionTechnology technology =
|
||||
location::nearby::proto::connections::
|
||||
CONNECTION_TECHNOLOGY_UNKNOWN_TECHNOLOGY;
|
||||
location::nearby::proto::connections::ConnectionBand band =
|
||||
location::nearby::proto::connections::CONNECTION_BAND_UNKNOWN_BAND;
|
||||
int frequency = -1; // -1 as Unknown.
|
||||
int try_count = 0;
|
||||
std::string network_operator = {};
|
||||
std::string country_code = {};
|
||||
bool is_tdls_used = false;
|
||||
bool wifi_hotspot_enabled = false;
|
||||
int max_wifi_tx_speed = 0;
|
||||
int max_wifi_rx_speed = 0;
|
||||
int channel_width = -1; // -1 as Unknown.
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
#endif // ANALYTICS_CONNECTION_ATTEMPT_METADATA_PARAMS_H_
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "platform/public/mutex.h"
|
||||
#include "platform/public/mutex_lock.h"
|
||||
#include "proto/connections_enums.pb.h"
|
||||
#include "proto/connections_enums.proto.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
@@ -94,7 +95,29 @@ Exception WriteInt(OutputStream* writer, std::int32_t value) {
|
||||
BaseEndpointChannel::BaseEndpointChannel(const std::string& channel_name,
|
||||
InputStream* reader,
|
||||
OutputStream* writer)
|
||||
: channel_name_(channel_name), reader_(reader), writer_(writer) {}
|
||||
: BaseEndpointChannel(
|
||||
channel_name, reader, writer,
|
||||
// TODO(edwinwu): Below values should be retrieved from a base socket,
|
||||
// the #MediumSocket in Android counterpart, from which all the
|
||||
// derived medium sockets should dervied, and implement the supported
|
||||
// values and leave the default values in base #MediumSocket.
|
||||
/*ConnectionTechnology*/
|
||||
proto::connections::CONNECTION_TECHNOLOGY_UNKNOWN_TECHNOLOGY,
|
||||
/*ConnectionBand*/ proto::connections::CONNECTION_BAND_UNKNOWN_BAND,
|
||||
/*frequency*/ -1,
|
||||
/*try_count*/ 0) {}
|
||||
|
||||
BaseEndpointChannel::BaseEndpointChannel(
|
||||
const std::string& channel_name, InputStream* reader, OutputStream* writer,
|
||||
proto::connections::ConnectionTechnology technology,
|
||||
proto::connections::ConnectionBand band, int frequency, int try_count)
|
||||
: channel_name_(channel_name),
|
||||
reader_(reader),
|
||||
writer_(writer),
|
||||
technology_(technology),
|
||||
band_(band),
|
||||
frequency_(frequency),
|
||||
try_count_(try_count) {}
|
||||
|
||||
ExceptionOr<ByteArray> BaseEndpointChannel::Read() {
|
||||
ByteArray result;
|
||||
@@ -335,6 +358,22 @@ absl::Time BaseEndpointChannel::GetLastWriteTimestamp() const {
|
||||
return last_write_timestamp_;
|
||||
}
|
||||
|
||||
proto::connections::ConnectionTechnology BaseEndpointChannel::GetTechnology()
|
||||
const {
|
||||
return technology_;
|
||||
}
|
||||
|
||||
// Returns the used wifi band of this EndpointChannel.
|
||||
proto::connections::ConnectionBand BaseEndpointChannel::GetBand() const {
|
||||
return band_;
|
||||
}
|
||||
|
||||
// Returns the used wifi frequency of this EndpointChannel.
|
||||
int BaseEndpointChannel::GetFrequency() const { return frequency_; }
|
||||
|
||||
// Returns the try count of this EndpointChannel.
|
||||
int BaseEndpointChannel::GetTryCount() const { return try_count_; }
|
||||
|
||||
bool BaseEndpointChannel::IsEncryptionEnabledLocked() const {
|
||||
return crypto_context_ != nullptr;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "platform/public/condition_variable.h"
|
||||
#include "platform/public/mutex.h"
|
||||
#include "platform/public/system_clock.h"
|
||||
#include "proto/connections_enums.proto.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
@@ -39,6 +40,11 @@ class BaseEndpointChannel : public EndpointChannel {
|
||||
public:
|
||||
BaseEndpointChannel(const std::string& channel_name, InputStream* reader,
|
||||
OutputStream* writer);
|
||||
BaseEndpointChannel(const std::string& channel_name, InputStream* reader,
|
||||
OutputStream* writer,
|
||||
proto::connections::ConnectionTechnology,
|
||||
proto::connections::ConnectionBand band, int frequency,
|
||||
int try_count);
|
||||
~BaseEndpointChannel() override = default;
|
||||
|
||||
ExceptionOr<ByteArray> Read()
|
||||
@@ -94,6 +100,18 @@ class BaseEndpointChannel : public EndpointChannel {
|
||||
absl::Time GetLastWriteTimestamp() const
|
||||
ABSL_LOCKS_EXCLUDED(last_write_mutex_) override;
|
||||
|
||||
// Returns the used technology of this EndpointChannel.
|
||||
proto::connections::ConnectionTechnology GetTechnology() const override;
|
||||
|
||||
// Returns the used wifi band of this EndpointChannel.
|
||||
proto::connections::ConnectionBand GetBand() const override;
|
||||
|
||||
// Returns the used wifi frequency of this EndpointChannel.
|
||||
int GetFrequency() const override;
|
||||
|
||||
// Returns the try count of this EndpointChannel.
|
||||
int GetTryCount() const override;
|
||||
|
||||
void SetAnalyticsRecorder(analytics::AnalyticsRecorder* analytics_recorder,
|
||||
const std::string& endpoint_id) override;
|
||||
|
||||
@@ -145,6 +163,12 @@ class BaseEndpointChannel : public EndpointChannel {
|
||||
// If true, writes should block until this has been set to false.
|
||||
bool is_paused_ ABSL_GUARDED_BY(is_paused_mutex_) = false;
|
||||
|
||||
// The medium technology information of this endpoint channel.
|
||||
proto::connections::ConnectionTechnology technology_;
|
||||
proto::connections::ConnectionBand band_;
|
||||
int frequency_;
|
||||
int try_count_;
|
||||
|
||||
analytics::AnalyticsRecorder* analytics_recorder_ = nullptr;
|
||||
std::string endpoint_id_ = "";
|
||||
};
|
||||
|
||||
@@ -391,18 +391,7 @@ void BasePcpHandler::OnEncryptionSuccessRunnable(
|
||||
std::move(connection_info.channel), connection_info.listener,
|
||||
connection_info.connection_token);
|
||||
|
||||
if (connection_info.is_incoming) {
|
||||
connection_info.client->GetAnalyticsRecorder().OnIncomingConnectionAttempt(
|
||||
proto::connections::INITIAL, medium, proto::connections::RESULT_SUCCESS,
|
||||
SystemClock::ElapsedRealtime() - connection_info.start_time,
|
||||
connection_info.connection_token);
|
||||
} else {
|
||||
connection_info.client->GetAnalyticsRecorder().OnOutgoingConnectionAttempt(
|
||||
endpoint_id, proto::connections::INITIAL, medium,
|
||||
proto::connections::RESULT_SUCCESS,
|
||||
SystemClock::ElapsedRealtime() - connection_info.start_time,
|
||||
connection_info.connection_token);
|
||||
}
|
||||
LogConnectionAttemptSuccess(endpoint_id, connection_info);
|
||||
|
||||
if (auto future_status = connection_info.result.lock()) {
|
||||
NEARBY_LOGS(INFO) << "Connection established; Finalising future OK.";
|
||||
@@ -503,7 +492,6 @@ Status BasePcpHandler::RequestConnection(ClientProxy* client,
|
||||
ConnectImplResult connect_impl_result;
|
||||
|
||||
for (auto connect_endpoint : discovered_endpoints) {
|
||||
absl::Time connect_start_time = SystemClock::ElapsedRealtime();
|
||||
if (!MediumSupportedByClientOptions(connect_endpoint->medium,
|
||||
options))
|
||||
continue;
|
||||
@@ -511,10 +499,6 @@ Status BasePcpHandler::RequestConnection(ClientProxy* client,
|
||||
if (connect_impl_result.status.Ok()) {
|
||||
channel = std::move(connect_impl_result.endpoint_channel);
|
||||
break;
|
||||
} else {
|
||||
LogConnectionAttempt(client, connect_endpoint->medium,
|
||||
connect_endpoint->endpoint_id,
|
||||
/* is_incoming = */ false, connect_start_time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -720,7 +704,8 @@ void BasePcpHandler::ProcessPreConnectionInitiationFailure(
|
||||
result->Set(status);
|
||||
}
|
||||
|
||||
LogConnectionAttempt(client, medium, endpoint_id, is_incoming, start_time);
|
||||
LogConnectionAttemptFailure(client, medium, endpoint_id, is_incoming,
|
||||
start_time, channel);
|
||||
// result is hold inside a swapper, and saved in PendingConnectionInfo.
|
||||
// PendingConnectionInfo destructor will clear the memory of SettableFuture
|
||||
// shared_ptr for result.
|
||||
@@ -1079,10 +1064,9 @@ Exception BasePcpHandler::OnIncomingConnection(
|
||||
<< "Failed to parse incoming connection request; client="
|
||||
<< client->GetClientId()
|
||||
<< "; device=" << absl::BytesToHexString(remote_endpoint_info.data());
|
||||
ProcessPreConnectionInitiationFailure(client, medium, "", channel.get(),
|
||||
/* is_incoming= */ false,
|
||||
start_time, {Status::kError},
|
||||
nullptr);
|
||||
ProcessPreConnectionInitiationFailure(
|
||||
client, medium, "", channel.get(),
|
||||
/* is_incoming= */ false, start_time, {Status::kError}, nullptr);
|
||||
return {Exception::kSuccess};
|
||||
}
|
||||
return wrapped_frame.GetException();
|
||||
@@ -1466,23 +1450,63 @@ std::string BasePcpHandler::GetHashedConnectionToken(
|
||||
.substr(0, kConnectionTokenLength);
|
||||
}
|
||||
|
||||
void BasePcpHandler::LogConnectionAttempt(ClientProxy* client, Medium medium,
|
||||
const std::string& endpoint_id,
|
||||
bool is_incoming,
|
||||
absl::Time start_time) {
|
||||
void BasePcpHandler::LogConnectionAttemptFailure(
|
||||
ClientProxy* client, Medium medium, const std::string& endpoint_id,
|
||||
bool is_incoming, absl::Time start_time,
|
||||
EndpointChannel* endpoint_channel) {
|
||||
proto::connections::ConnectionAttemptResult result =
|
||||
Cancelled(client, endpoint_id) ? proto::connections::RESULT_CANCELLED
|
||||
: proto::connections::RESULT_ERROR;
|
||||
std::unique_ptr<ConnectionAttemptMetadataParams>
|
||||
connections_attempt_metadata_params;
|
||||
if (endpoint_channel != nullptr) {
|
||||
connections_attempt_metadata_params =
|
||||
client->GetAnalyticsRecorder().BuildConnectionAttemptMetadataParams(
|
||||
endpoint_channel->GetTechnology(), endpoint_channel->GetBand(),
|
||||
endpoint_channel->GetFrequency(), endpoint_channel->GetTryCount());
|
||||
}
|
||||
if (is_incoming) {
|
||||
client->GetAnalyticsRecorder().OnIncomingConnectionAttempt(
|
||||
proto::connections::INITIAL, medium, result,
|
||||
SystemClock::ElapsedRealtime() - start_time,
|
||||
/* connection_token= */ "");
|
||||
/* connection_token= */ "", connections_attempt_metadata_params.get());
|
||||
} else {
|
||||
client->GetAnalyticsRecorder().OnOutgoingConnectionAttempt(
|
||||
endpoint_id, proto::connections::INITIAL, medium, result,
|
||||
SystemClock::ElapsedRealtime() - start_time,
|
||||
/* connection_token= */ "");
|
||||
/* connection_token= */ "", connections_attempt_metadata_params.get());
|
||||
}
|
||||
}
|
||||
|
||||
void BasePcpHandler::LogConnectionAttemptSuccess(
|
||||
const std::string& endpoint_id,
|
||||
const PendingConnectionInfo& connection_info) {
|
||||
std::unique_ptr<ConnectionAttemptMetadataParams>
|
||||
connections_attempt_metadata_params;
|
||||
if (connection_info.channel != nullptr) {
|
||||
connections_attempt_metadata_params =
|
||||
connection_info.client->GetAnalyticsRecorder()
|
||||
.BuildConnectionAttemptMetadataParams(
|
||||
connection_info.channel->GetTechnology(),
|
||||
connection_info.channel->GetBand(),
|
||||
connection_info.channel->GetFrequency(),
|
||||
connection_info.channel->GetTryCount());
|
||||
}
|
||||
if (connection_info.is_incoming) {
|
||||
connection_info.client->GetAnalyticsRecorder().OnIncomingConnectionAttempt(
|
||||
proto::connections::INITIAL, connection_info.channel->GetMedium(),
|
||||
proto::connections::RESULT_SUCCESS,
|
||||
SystemClock::ElapsedRealtime() - connection_info.start_time,
|
||||
connection_info.connection_token,
|
||||
connections_attempt_metadata_params.get());
|
||||
} else {
|
||||
connection_info.client->GetAnalyticsRecorder().OnOutgoingConnectionAttempt(
|
||||
endpoint_id, proto::connections::INITIAL,
|
||||
connection_info.channel->GetMedium(),
|
||||
proto::connections::RESULT_SUCCESS,
|
||||
SystemClock::ElapsedRealtime() - connection_info.start_time,
|
||||
connection_info.connection_token,
|
||||
connections_attempt_metadata_params.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -458,9 +458,15 @@ class BasePcpHandler : public PcpHandler,
|
||||
// array.
|
||||
std::string GetHashedConnectionToken(const ByteArray& token_bytes);
|
||||
|
||||
static void LogConnectionAttempt(ClientProxy* client, Medium medium,
|
||||
const std::string& endpoint_id,
|
||||
bool is_incoming, absl::Time start_time);
|
||||
static void LogConnectionAttemptFailure(ClientProxy* client, Medium medium,
|
||||
const std::string& endpoint_id,
|
||||
bool is_incoming,
|
||||
absl::Time start_time,
|
||||
EndpointChannel* endpoint_channel);
|
||||
|
||||
static void LogConnectionAttemptSuccess(
|
||||
const std::string& endpoint_id,
|
||||
const PendingConnectionInfo& connection_info);
|
||||
|
||||
// Returns true if the client cancels the operation in progress through the
|
||||
// endpoint id. This is done by CancellationFlag.
|
||||
|
||||
@@ -439,11 +439,21 @@ void BwuManager::OnIncomingConnection(
|
||||
CHECK(client == mapped_client);
|
||||
|
||||
// The ConnectionAttempt has now succeeded, so record it as such.
|
||||
std::unique_ptr<ConnectionAttemptMetadataParams>
|
||||
connections_attempt_metadata_params;
|
||||
if (channel != nullptr) {
|
||||
connections_attempt_metadata_params =
|
||||
client->GetAnalyticsRecorder()
|
||||
.BuildConnectionAttemptMetadataParams(
|
||||
channel->GetTechnology(), channel->GetBand(),
|
||||
channel->GetFrequency(), channel->GetTryCount());
|
||||
}
|
||||
client->GetAnalyticsRecorder().OnIncomingConnectionAttempt(
|
||||
proto::connections::UPGRADE, channel->GetMedium(),
|
||||
proto::connections::RESULT_SUCCESS,
|
||||
SystemClock::ElapsedRealtime() - connection_attempt_start_time,
|
||||
client->GetConnectionToken(endpoint_id));
|
||||
client->GetConnectionToken(endpoint_id),
|
||||
connections_attempt_metadata_params.get());
|
||||
|
||||
// Use the introductory client information sent over to run the upgrade
|
||||
// protocol.
|
||||
@@ -585,11 +595,20 @@ void BwuManager::ProcessBwuPathAvailableEvent(
|
||||
connection_attempt_result = proto::connections::RESULT_ERROR;
|
||||
}
|
||||
|
||||
std::unique_ptr<ConnectionAttemptMetadataParams>
|
||||
connections_attempt_metadata_params;
|
||||
if (channel != nullptr) {
|
||||
connections_attempt_metadata_params =
|
||||
client->GetAnalyticsRecorder().BuildConnectionAttemptMetadataParams(
|
||||
channel->GetTechnology(), channel->GetBand(),
|
||||
channel->GetFrequency(), channel->GetTryCount());
|
||||
}
|
||||
client->GetAnalyticsRecorder().OnOutgoingConnectionAttempt(
|
||||
endpoint_id, proto::connections::UPGRADE, medium_,
|
||||
connection_attempt_result,
|
||||
SystemClock::ElapsedRealtime() - connection_attempt_start_time,
|
||||
client->GetConnectionToken(endpoint_id));
|
||||
client->GetConnectionToken(endpoint_id),
|
||||
connections_attempt_metadata_params.get());
|
||||
|
||||
if (channel == nullptr) {
|
||||
NEARBY_LOGS(INFO) << "Failed to get new channel.";
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace location {
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
// CLientProxy is tracking state of client's connection, and serves as
|
||||
// ClientProxy is tracking state of client's connection, and serves as
|
||||
// a proxy for notifications sent to this client.
|
||||
class ClientProxy final {
|
||||
public:
|
||||
|
||||
@@ -57,6 +57,18 @@ class EndpointChannel {
|
||||
// Returns the analytics enum representing the medium of this EndpointChannel.
|
||||
virtual proto::connections::Medium GetMedium() const = 0;
|
||||
|
||||
// Returns the used BLE or WiFi technology of this EndpointChannel.
|
||||
virtual proto::connections::ConnectionTechnology GetTechnology() const = 0;
|
||||
|
||||
// Returns the used wifi band of this EndpointChannel.
|
||||
virtual proto::connections::ConnectionBand GetBand() const = 0;
|
||||
|
||||
// Returns the used wifi frequency of this EndpointChannel.
|
||||
virtual int GetFrequency() const = 0;
|
||||
|
||||
// Returns the try counts of this EndpointChannel.
|
||||
virtual int GetTryCount() const = 0;
|
||||
|
||||
// Returns the maximum supported transmit packet size(MTU) for the underlying
|
||||
// transport.
|
||||
virtual int GetMaxTransmitPacketSize() const = 0;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
// A struct to consturct error code parameters for the analytics recorder.
|
||||
// A struct to construct error code parameters for the analytics recorder.
|
||||
struct ErrorCodeParams {
|
||||
location::nearby::proto::connections::Medium medium =
|
||||
location::nearby::proto::connections::UNKNOWN_MEDIUM;
|
||||
|
||||
Reference in New Issue
Block a user