Skip to content

Commit

Permalink
Change node_id from hash to account in telemetry RPC/websocket (#2843)
Browse files Browse the repository at this point in the history
  • Loading branch information
wezrule authored and guilhermelawless committed Jul 14, 2020
1 parent d7d777a commit f0f9a6b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion nano/lib/numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,23 @@ std::string nano::public_key::to_node_id () const
return to_account ().replace (0, 4, "node");
}

bool nano::public_key::decode_node_id (std::string const & source_a)
{
return decode_account (source_a);
}

bool nano::public_key::decode_account (std::string const & source_a)
{
auto error (source_a.size () < 5);
if (!error)
{
auto xrb_prefix (source_a[0] == 'x' && source_a[1] == 'r' && source_a[2] == 'b' && (source_a[3] == '_' || source_a[3] == '-'));
auto nano_prefix (source_a[0] == 'n' && source_a[1] == 'a' && source_a[2] == 'n' && source_a[3] == 'o' && (source_a[4] == '_' || source_a[4] == '-'));
auto node_id_prefix = (source_a[0] == 'n' && source_a[1] == 'o' && source_a[2] == 'd' && source_a[3] == 'e' && source_a[4] == '_');
error = (xrb_prefix && source_a.size () != 64) || (nano_prefix && source_a.size () != 65);
if (!error)
{
if (xrb_prefix || nano_prefix)
if (xrb_prefix || nano_prefix || node_id_prefix)
{
auto i (source_a.begin () + (xrb_prefix ? 4 : 5));
if (*i == '1' || *i == '3')
Expand Down
1 change: 1 addition & 0 deletions nano/lib/numbers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class public_key final : public uint256_union
using uint256_union::uint256_union;

std::string to_node_id () const;
bool decode_node_id (std::string const & source_a);
void encode_account (std::string &) const;
std::string to_account () const;
bool decode_account (std::string const &);
Expand Down
4 changes: 2 additions & 2 deletions nano/node/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ nano::error nano::telemetry_data::serialize_json (nano::jsonconfig & json, bool
// Keep these last for UI purposes
if (!ignore_identification_metrics_a)
{
json.put ("node_id", node_id.to_string ());
json.put ("node_id", node_id.to_node_id ());
json.put ("signature", signature.to_string ());
}
return json.get_error ();
Expand All @@ -1276,7 +1276,7 @@ nano::error nano::telemetry_data::deserialize_json (nano::jsonconfig & json, boo
json.get ("node_id", node_id_l);
if (!json.get_error ())
{
if (node_id.decode_hex (node_id_l))
if (node_id.decode_node_id (node_id_l))
{
json.get_error ().set ("Could not deserialize node id");
}
Expand Down
1 change: 1 addition & 0 deletions nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8852,6 +8852,7 @@ TEST (rpc, telemetry_all)

ASSERT_EQ (node->network.endpoint ().address ().to_string (), metrics.get<std::string> ("address"));
ASSERT_EQ (node->network.endpoint ().port (), metrics.get<uint16_t> ("port"));
ASSERT_TRUE (node1.network.find_node_id (data.node_id));
}

// Also tests all forms of ipv4/ipv6
Expand Down

0 comments on commit f0f9a6b

Please sign in to comment.