Change node_id from hash to account in telemetry RPC/websocket (#2843)

This commit is contained in:
Wesley Shillingford 2020-07-14 13:18:15 +01:00 committed by GitHub
commit 1111079e67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 3 deletions

View file

@ -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')

View file

@ -116,6 +116,7 @@ public:
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 &);

View file

@ -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");
}

View file

@ -7636,6 +7636,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