Skip to content

Commit

Permalink
Move parse_status and auxiliary functions to more appropriate names…
Browse files Browse the repository at this point in the history
…pace
  • Loading branch information
pwojcikdev committed Jan 25, 2024
1 parent 046be9a commit 6c0f5ef
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion nano/core_test/message_deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ auto message_deserializer_success_checker (message_type & message_original) -> v
ASSERT_EQ (*deserialized_bytes, *original_bytes);
});
// This is a sanity test, to ensure the successful deserialization case passes.
ASSERT_EQ (message_deserializer->status, nano::transport::message_deserializer::parse_status::success);
ASSERT_EQ (message_deserializer->status, nano::transport::parse_status::success);
}

TEST (message_deserializer, exact_confirm_ack)
Expand Down
4 changes: 2 additions & 2 deletions nano/node/transport/message_deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,14 @@ std::unique_ptr<nano::asc_pull_ack> nano::transport::message_deserializer::deser
return {};
}

nano::stat::detail nano::to_stat_detail (nano::transport::message_deserializer::parse_status status)
nano::stat::detail nano::transport::to_stat_detail (nano::transport::parse_status status)
{
auto value = magic_enum::enum_cast<nano::stat::detail> (magic_enum::enum_name (status));
debug_assert (value);
return value.value_or (nano::stat::detail{});
}

std::string_view nano::to_string (nano::transport::message_deserializer::parse_status status)
std::string_view nano::transport::to_string (nano::transport::parse_status status)
{
return magic_enum::enum_name (status);
}
56 changes: 28 additions & 28 deletions nano/node/transport/message_deserializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ namespace nano
{
namespace transport
{
enum class parse_status
{
none,
success,
insufficient_work,
invalid_header,
invalid_message_type,
invalid_keepalive_message,
invalid_publish_message,
invalid_confirm_req_message,
invalid_confirm_ack_message,
invalid_node_id_handshake_message,
invalid_telemetry_req_message,
invalid_telemetry_ack_message,
invalid_bulk_pull_message,
invalid_bulk_pull_account_message,
invalid_frontier_req_message,
invalid_asc_pull_req_message,
invalid_asc_pull_ack_message,
invalid_network,
outdated_version,
duplicate_publish_message,
message_size_too_big,
};

class message_deserializer : public std::enable_shared_from_this<nano::transport::message_deserializer>
{
public:
enum class parse_status
{
none,
success,
insufficient_work,
invalid_header,
invalid_message_type,
invalid_keepalive_message,
invalid_publish_message,
invalid_confirm_req_message,
invalid_confirm_ack_message,
invalid_node_id_handshake_message,
invalid_telemetry_req_message,
invalid_telemetry_ack_message,
invalid_bulk_pull_message,
invalid_bulk_pull_account_message,
invalid_frontier_req_message,
invalid_asc_pull_req_message,
invalid_asc_pull_ack_message,
invalid_network,
outdated_version,
duplicate_publish_message,
message_size_too_big,
};

using callback_type = std::function<void (boost::system::error_code, std::unique_ptr<nano::message>)>;

parse_status status;
Expand Down Expand Up @@ -90,8 +90,8 @@ namespace transport
nano::vote_uniquer & vote_uniquer_m;
read_query read_op;
};
}

nano::stat::detail to_stat_detail (nano::transport::message_deserializer::parse_status);
std::string_view to_string (nano::transport::message_deserializer::parse_status);
nano::stat::detail to_stat_detail (parse_status);
std::string_view to_string (parse_status);
}
}
12 changes: 6 additions & 6 deletions nano/node/transport/tcp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ void nano::transport::tcp_server::receive_message ()
if (ec)
{
// IO error or critical error when deserializing message
node->stats.inc (nano::stat::type::error, nano::to_stat_detail (this_l->message_deserializer->status));
node->stats.inc (nano::stat::type::error, to_stat_detail (this_l->message_deserializer->status));
node->logger.debug (nano::log::type::tcp_server, "Error reading message: {}, status: {} ({})",
ec.message (),
nano::to_string (this_l->message_deserializer->status),
to_string (this_l->message_deserializer->status),
nano::util::to_str (this_l->remote_endpoint));

this_l->stop ();
Expand All @@ -402,18 +402,18 @@ void nano::transport::tcp_server::received_message (std::unique_ptr<nano::messag
else
{
// Error while deserializing message
debug_assert (message_deserializer->status != transport::message_deserializer::parse_status::success);
debug_assert (message_deserializer->status != transport::parse_status::success);

node->stats.inc (nano::stat::type::error, nano::to_stat_detail (message_deserializer->status));
if (message_deserializer->status == transport::message_deserializer::parse_status::duplicate_publish_message)
node->stats.inc (nano::stat::type::error, to_stat_detail (message_deserializer->status));
if (message_deserializer->status == transport::parse_status::duplicate_publish_message)
{
node->stats.inc (nano::stat::type::filter, nano::stat::detail::duplicate_publish_message);
}
else
{
// Avoid too much noise about `duplicate_publish_message` errors
node->logger.debug (nano::log::type::tcp_server, "Error deserializing message: {} ({})",
nano::to_string (message_deserializer->status),
to_string (message_deserializer->status),
nano::util::to_str (remote_endpoint));
}
}
Expand Down

0 comments on commit 6c0f5ef

Please sign in to comment.