diff --git a/nano/lib/numbers.cpp b/nano/lib/numbers.cpp index bffd37e396..2b83972b0a 100644 --- a/nano/lib/numbers.cpp +++ b/nano/lib/numbers.cpp @@ -65,6 +65,11 @@ 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); @@ -72,10 +77,11 @@ bool nano::public_key::decode_account (std::string const & source_a) { 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') diff --git a/nano/lib/numbers.hpp b/nano/lib/numbers.hpp index 1be15455c2..3e84d0221a 100644 --- a/nano/lib/numbers.hpp +++ b/nano/lib/numbers.hpp @@ -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 &); diff --git a/nano/node/common.cpp b/nano/node/common.cpp index 3a4a7a6bce..dbb660326b 100644 --- a/nano/node/common.cpp +++ b/nano/node/common.cpp @@ -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 (); @@ -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"); } diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index aa6e9ee858..067ebee769 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -7636,6 +7636,7 @@ TEST (rpc, telemetry_all) ASSERT_EQ (node->network.endpoint ().address ().to_string (), metrics.get ("address")); ASSERT_EQ (node->network.endpoint ().port (), metrics.get ("port")); + ASSERT_TRUE (node1.network.find_node_id (data.node_id)); } // Also tests all forms of ipv4/ipv6