Skip to content

Commit

Permalink
Use channel as telemetry data key
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Aug 7, 2024
1 parent b7ae57a commit 86cd7d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
11 changes: 4 additions & 7 deletions nano/node/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,19 @@ void nano::telemetry::process (const nano::telemetry_ack & telemetry, const std:

nano::unique_lock<nano::mutex> lock{ mutex };

const auto endpoint = channel->get_endpoint ();

if (auto it = telemetries.get<tag_endpoint> ().find (endpoint); it != telemetries.get<tag_endpoint> ().end ())
if (auto it = telemetries.get<tag_channel> ().find (channel); it != telemetries.get<tag_channel> ().end ())
{
stats.inc (nano::stat::type::telemetry, nano::stat::detail::update);

telemetries.get<tag_endpoint> ().modify (it, [&telemetry, &endpoint] (auto & entry) {
debug_assert (entry.endpoint == endpoint);
telemetries.get<tag_channel> ().modify (it, [&telemetry, &channel] (auto & entry) {
entry.data = telemetry.data;
entry.last_updated = std::chrono::steady_clock::now ();
});
}
else
{
stats.inc (nano::stat::type::telemetry, nano::stat::detail::insert);
telemetries.get<tag_endpoint> ().insert ({ endpoint, telemetry.data, std::chrono::steady_clock::now (), channel });
telemetries.get<tag_channel> ().insert ({ channel, telemetry.data, std::chrono::steady_clock::now () });

if (telemetries.size () > max_size)
{
Expand Down Expand Up @@ -283,7 +280,7 @@ std::unordered_map<nano::endpoint, nano::telemetry_data> nano::telemetry::get_al
{
if (check_timeout (entry))
{
result[entry.endpoint] = entry.data;
result[entry.endpoint ()] = entry.data;
}
}
return result;
Expand Down
15 changes: 11 additions & 4 deletions nano/node/telemetry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ class telemetry
private:
struct entry
{
nano::endpoint endpoint;
std::shared_ptr<nano::transport::channel> channel;
nano::telemetry_data data;
std::chrono::steady_clock::time_point last_updated;
std::shared_ptr<nano::transport::channel> channel;

nano::endpoint endpoint () const
{
return channel->get_endpoint ();
}
};

private:
Expand All @@ -124,13 +128,16 @@ class telemetry
private:
// clang-format off
class tag_sequenced {};
class tag_channel {};
class tag_endpoint {};

using ordered_telemetries = boost::multi_index_container<entry,
mi::indexed_by<
mi::sequenced<mi::tag<tag_sequenced>>,
mi::hashed_unique<mi::tag<tag_endpoint>,
mi::member<entry, nano::endpoint, &entry::endpoint>>
mi::ordered_unique<mi::tag<tag_channel>,
mi::member<entry, std::shared_ptr<nano::transport::channel>, &entry::channel>>,
mi::hashed_non_unique<mi::tag<tag_endpoint>,
mi::const_mem_fun<entry, nano::endpoint, &entry::endpoint>>
>>;
// clang-format on

Expand Down

0 comments on commit 86cd7d9

Please sign in to comment.