Skip to content

Commit

Permalink
sentry: move make_client_id to ApplicationInfo (#2365)
Browse files Browse the repository at this point in the history
  • Loading branch information
battlmonstr authored Sep 20, 2024
1 parent e49e1d2 commit cf1073e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
3 changes: 2 additions & 1 deletion cmd/sentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <grpcpp/grpcpp.h>

#include <silkworm/buildinfo.h>
#include <silkworm/infra/common/application_info.hpp>
#include <silkworm/infra/common/log.hpp>
#include <silkworm/infra/concurrency/awaitable_wait_for_one.hpp>
#include <silkworm/infra/grpc/client/client_context_pool.hpp>
Expand All @@ -41,7 +42,7 @@ Settings sentry_parse_cli_settings(int argc, char* argv[]) {
CLI::App cli{"Sentry - P2P proxy"};

Settings settings;
settings.client_id = Sentry::make_client_id(*silkworm_get_buildinfo());
settings.client_id = make_client_id_from_build_info(*silkworm_get_buildinfo());

add_logging_options(cli, settings.log_settings);
add_option_data_dir(cli, settings.data_dir_path);
Expand Down
3 changes: 1 addition & 2 deletions cmd/silkworm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <silkworm/infra/concurrency/awaitable_wait_for_one.hpp>
#include <silkworm/infra/grpc/client/client_context_pool.hpp>
#include <silkworm/node/node.hpp>
#include <silkworm/sentry/sentry.hpp>

#include "common/common.hpp"
#include "common/db_checklist.hpp"
Expand Down Expand Up @@ -195,7 +194,7 @@ void parse_silkworm_command_line(CLI::App& cli, int argc, char* argv[], node::Se
snapshot_settings.bittorrent_settings.repository_path = snapshot_settings.repository_dir;

// sentry::Settings
settings.sentry_settings.client_id = sentry::Sentry::make_client_id(*build_info);
settings.sentry_settings.client_id = node_settings.build_info.client_id;
settings.sentry_settings.data_dir_path = node_settings.data_directory->path();
settings.sentry_settings.network_id = node_settings.network_id;
}
Expand Down
11 changes: 10 additions & 1 deletion silkworm/infra/common/application_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
namespace silkworm {

std::string get_node_name_from_build_info(const buildinfo* info) {
std::string node_name{"silkworm/"};
std::string node_name = info->project_name;
node_name.append("/");
node_name.append(info->git_branch);
node_name.append(info->project_version);
node_name.append("/");
Expand All @@ -37,6 +38,13 @@ std::string get_node_name_from_build_info(const buildinfo* info) {
return node_name;
}

std::string make_client_id_from_build_info(const buildinfo& info) {
return std::string(info.project_name) +
"/v" + info.project_version +
"/" + info.system_name + "-" + info.system_processor +
"/" + info.compiler_id + "-" + info.compiler_version;
}

std::string get_description_from_build_info(const buildinfo* info) {
std::string description{"version: "};
description.append(info->git_branch);
Expand All @@ -60,6 +68,7 @@ ApplicationInfo make_application_info(const buildinfo* info) {
.commit_hash = info->git_commit_hash,
.build_description = get_description_from_build_info(info),
.node_name = get_node_name_from_build_info(info),
.client_id = make_client_id_from_build_info(*info),
};
}

Expand Down
4 changes: 4 additions & 0 deletions silkworm/infra/common/application_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ struct ApplicationInfo {
std::string commit_hash; // Extracted from version control system
std::string build_description; // Containing compiler and platform
std::string node_name; // Complete node name with identifier and build info
std::string client_id; // P2P RLPx clientId
};

//! Assemble the complete node name using the Cable build information
std::string get_node_name_from_build_info(const buildinfo* info);

//! P2P RLPx clientId from the Cable build information
std::string make_client_id_from_build_info(const buildinfo& info);

//! Assemble the build description using the Cable build information
std::string get_description_from_build_info(const buildinfo* info);

Expand Down
7 changes: 0 additions & 7 deletions silkworm/sentry/sentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,6 @@ Task<void> SentryImpl::run_grpc_server() {
}
}

std::string Sentry::make_client_id(const buildinfo& info) {
return std::string(info.project_name) +
"/v" + info.project_version +
"/" + info.system_name + "-" + info.system_processor +
"/" + info.compiler_id + "-" + info.compiler_version;
}

std::string SentryImpl::client_id() const {
return settings_.client_id;
}
Expand Down
2 changes: 0 additions & 2 deletions silkworm/sentry/sentry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class Sentry final : public api::SentryClient {
void on_disconnect(std::function<Task<void>()> callback) override;
Task<void> reconnect() override;

static std::string make_client_id(const buildinfo& info);

private:
std::unique_ptr<SentryImpl> p_impl_;
};
Expand Down

0 comments on commit cf1073e

Please sign in to comment.