Skip to content

Commit

Permalink
Use node_ prefix for node ID (#2191)
Browse files Browse the repository at this point in the history
* Use node_ prefix for node ID
* Return field "node_id"
  • Loading branch information
SergiySW authored Aug 5, 2019
1 parent 6d6b2b2 commit 83e5c50
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions nano/lib/numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ std::string nano::uint256_union::to_account () const
return result;
}

std::string nano::uint256_union::to_node_id () const
{
return to_account ().replace (0, 4, "node");
}

bool nano::uint256_union::decode_account (std::string const & source_a)
{
auto error (source_a.size () < 5);
Expand Down
1 change: 1 addition & 0 deletions nano/lib/numbers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ union uint256_union final
bool decode_dec (std::string const &);
void encode_account (std::string &) const;
std::string to_account () const;
std::string to_node_id () const;
bool decode_account (std::string const &);
std::array<uint8_t, 32> bytes;
std::array<char, 32> chars;
Expand Down
3 changes: 2 additions & 1 deletion nano/node/json_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2502,6 +2502,7 @@ void nano::json_handler::node_id ()
response_l.put ("private", node.node_id.prv.data.to_string ());
response_l.put ("public", node.node_id.pub.to_string ());
response_l.put ("as_account", node.node_id.pub.to_account ());
response_l.put ("node_id", node.node_id.pub.to_node_id ());
}
response_errors ();
}
Expand Down Expand Up @@ -2588,7 +2589,7 @@ void nano::json_handler::peers ()
auto node_id_l (channel->get_node_id_optional ());
if (node_id_l.is_initialized ())
{
pending_tree.put ("node_id", node_id_l.get ().to_account ());
pending_tree.put ("node_id", node_id_l.get ().to_node_id ());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion nano/node/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void nano::network::send_node_id_handshake (std::shared_ptr<nano::transport::cha
nano::node_id_handshake message (query, response);
if (node.config.logging.network_node_id_handshake_logging ())
{
node.logger.try_log (boost::str (boost::format ("Node ID handshake sent with node ID %1% to %2%: query %3%, respond_to %4% (signature %5%)") % node.node_id.pub.to_account () % channel_a->get_endpoint () % (query ? query->to_string () : std::string ("[none]")) % (respond_to ? respond_to->to_string () : std::string ("[none]")) % (response ? response->second.to_string () : std::string ("[none]"))));
node.logger.try_log (boost::str (boost::format ("Node ID handshake sent with node ID %1% to %2%: query %3%, respond_to %4% (signature %5%)") % node.node_id.pub.to_node_id () % channel_a->get_endpoint () % (query ? query->to_string () : std::string ("[none]")) % (respond_to ? respond_to->to_string () : std::string ("[none]")) % (response ? response->second.to_string () : std::string ("[none]"))));
}
channel_a->send (message);
}
Expand Down
2 changes: 1 addition & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ startup_time (std::chrono::steady_clock::now ())
}

node_id = nano::keypair ();
logger.always_log ("Node ID: ", node_id.pub.to_account ());
logger.always_log ("Node ID: ", node_id.pub.to_node_id ());

const uint8_t * weight_buffer = network_params.network.is_live_network () ? nano_bootstrap_weights_live : nano_bootstrap_weights_beta;
size_t weight_size = network_params.network.is_live_network () ? nano_bootstrap_weights_live_size : nano_bootstrap_weights_beta_size;
Expand Down
4 changes: 2 additions & 2 deletions nano/node/transport/tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ void nano::transport::tcp_channels::start_tcp (nano::endpoint const & endpoint_a
auto bytes = message.to_bytes ();
if (node_l->config.logging.network_node_id_handshake_logging ())
{
node_l->logger.try_log (boost::str (boost::format ("Node ID handshake request sent with node ID %1% to %2%: query %3%") % node_l->node_id.pub.to_account () % endpoint_a % (*cookie).to_string ()));
node_l->logger.try_log (boost::str (boost::format ("Node ID handshake request sent with node ID %1% to %2%: query %3%") % node_l->node_id.pub.to_node_id () % endpoint_a % (*cookie).to_string ()));
}
std::shared_ptr<std::vector<uint8_t>> receive_buffer (std::make_shared<std::vector<uint8_t>> ());
receive_buffer->resize (256);
Expand Down Expand Up @@ -561,7 +561,7 @@ void nano::transport::tcp_channels::start_tcp_receive_node_id (std::shared_ptr<n
auto bytes = response_message.to_bytes ();
if (node_l->config.logging.network_node_id_handshake_logging ())
{
node_l->logger.try_log (boost::str (boost::format ("Node ID handshake response sent with node ID %1% to %2%: query %3%") % node_l->node_id.pub.to_account () % endpoint_a % (*message.query).to_string ()));
node_l->logger.try_log (boost::str (boost::format ("Node ID handshake response sent with node ID %1% to %2%: query %3%") % node_l->node_id.pub.to_node_id () % endpoint_a % (*message.query).to_string ()));
}
channel_a->send_buffer (bytes, nano::stat::detail::node_id_handshake, [node_w, channel_a, endpoint_a, callback_a](boost::system::error_code const & ec, size_t size_a) {
if (auto node_l = node_w.lock ())
Expand Down
2 changes: 1 addition & 1 deletion nano/node/transport/udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class udp_message_visitor : public nano::message_visitor
{
if (node.config.logging.network_node_id_handshake_logging ())
{
node.logger.try_log (boost::str (boost::format ("Received node_id_handshake message from %1% with query %2% and response account %3%") % endpoint % (message_a.query ? message_a.query->to_string () : std::string ("[none]")) % (message_a.response ? message_a.response->first.to_account () : std::string ("[none]"))));
node.logger.try_log (boost::str (boost::format ("Received node_id_handshake message from %1% with query %2% and response ID %3%") % endpoint % (message_a.query ? message_a.query->to_string () : std::string ("[none]")) % (message_a.response ? message_a.response->first.to_node_id () : std::string ("[none]"))));
}
boost::optional<nano::uint256_union> out_query;
boost::optional<nano::uint256_union> out_respond_to;
Expand Down
3 changes: 2 additions & 1 deletion nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2198,7 +2198,7 @@ TEST (rpc, peers_node_id)
ASSERT_EQ (2, peers_node.size ());
auto tree1 (peers_node.get_child ("[::1]:24001"));
ASSERT_EQ (std::to_string (nano::protocol_version), tree1.get<std::string> ("protocol_version"));
ASSERT_EQ (system.nodes[1]->node_id.pub.to_account (), tree1.get<std::string> ("node_id"));
ASSERT_EQ (system.nodes[1]->node_id.pub.to_node_id (), tree1.get<std::string> ("node_id"));
std::stringstream endpoint_text;
endpoint_text << endpoint;
auto tree2 (peers_node.get_child (endpoint_text.str ()));
Expand Down Expand Up @@ -5886,6 +5886,7 @@ TEST (rpc, node_id)
ASSERT_EQ (200, response.status);
ASSERT_EQ (system.nodes[0]->node_id.prv.data.to_string (), response.json.get<std::string> ("private"));
ASSERT_EQ (system.nodes[0]->node_id.pub.to_account (), response.json.get<std::string> ("as_account"));
ASSERT_EQ (system.nodes[0]->node_id.pub.to_node_id (), response.json.get<std::string> ("as_node_id"));
}

TEST (rpc, stats_clear)
Expand Down

0 comments on commit 83e5c50

Please sign in to comment.