Create new node ID on each launch & support keepalive with preferred ports (#1885)
* Create new node ID with each node launch * Remove CLI delete_node_id * Draft send self port in 1st keepalive * Remove duplicate node ID for IPv4 & IPv6 * Support receiving keepalive port messages * network.replace_port test * Update test * Test deleting node ID * Formatting * Add config options for external IP address & port * Add UPnP external IP address to message
This commit is contained in:
parent
ac89b6490c
commit
170188213f
17 changed files with 170 additions and 103 deletions
|
@ -1557,6 +1557,12 @@ TEST (block_store, upgrade_v13_v14)
|
|||
ASSERT_FALSE (store.account_get (transaction, nano::genesis_account, account_info));
|
||||
ASSERT_EQ (account_info.confirmation_height, 0);
|
||||
ASSERT_LT (13, store.version_get (transaction));
|
||||
|
||||
// Test deleting node ID
|
||||
nano::uint256_union node_id_mdb_key (3);
|
||||
nano::mdb_val value;
|
||||
auto error_node_id (mdb_get (store.env.tx (transaction), store.meta, nano::mdb_val (node_id_mdb_key), value));
|
||||
ASSERT_EQ (error_node_id, MDB_NOTFOUND);
|
||||
}
|
||||
|
||||
// Test various confirmation height values as well as clearing them
|
||||
|
|
|
@ -1773,3 +1773,43 @@ TEST (bootstrap, tcp_listener_timeout_keepalive)
|
|||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
}
|
||||
|
||||
TEST (network, replace_port)
|
||||
{
|
||||
nano::system system (24000, 1);
|
||||
ASSERT_EQ (0, system.nodes[0]->network.size ());
|
||||
nano::node_init init1;
|
||||
auto node1 (std::make_shared<nano::node> (init1, system.io_ctx, 24001, nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
{
|
||||
auto channel (system.nodes[0]->network.udp_channels.insert (nano::endpoint (node1->network.endpoint ().address (), 23000), nano::protocol_version));
|
||||
if (channel)
|
||||
{
|
||||
channel->node_id = node1->node_id.pub;
|
||||
}
|
||||
}
|
||||
auto peers_list (system.nodes[0]->network.udp_channels.list (std::numeric_limits<size_t>::max ()));
|
||||
ASSERT_EQ (peers_list[0]->node_id.get (), node1->node_id.pub);
|
||||
nano::transport::channel_udp channel (system.nodes[0]->network.udp_channels, node1->network.endpoint ());
|
||||
system.nodes[0]->network.send_keepalive (channel);
|
||||
system.deadline_set (5s);
|
||||
while (!system.nodes[0]->network.udp_channels.channel (node1->network.endpoint ()))
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
system.deadline_set (5s);
|
||||
while (system.nodes[0]->network.udp_channels.size () > 1)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (system.nodes[0]->network.udp_channels.size (), 1);
|
||||
auto list1 (system.nodes[0]->network.udp_channels.list (1));
|
||||
ASSERT_EQ (node1->network.endpoint (), list1[0]->endpoint);
|
||||
auto list2 (node1->network.udp_channels.list (1));
|
||||
ASSERT_EQ (system.nodes[0]->network.endpoint (), list2[0]->endpoint);
|
||||
// Remove correct peer (same node ID)
|
||||
system.nodes[0]->network.udp_channels.clean_node_id (nano::endpoint (node1->network.endpoint ().address (), 23000), node1->node_id.pub);
|
||||
ASSERT_EQ (system.nodes[0]->network.udp_channels.size (), 0);
|
||||
node1->stop ();
|
||||
}
|
||||
|
|
|
@ -700,11 +700,15 @@ TEST (node_config, v16_v17_upgrade)
|
|||
ASSERT_FALSE (tree.get_optional_child ("tcp_client_timeout"));
|
||||
ASSERT_FALSE (tree.get_optional_child ("tcp_server_timeout"));
|
||||
ASSERT_FALSE (tree.get_optional_child ("pow_sleep_interval"));
|
||||
ASSERT_FALSE (tree.get_optional_child ("external_address"));
|
||||
ASSERT_FALSE (tree.get_optional_child ("external_port"));
|
||||
config.deserialize_json (upgraded, tree);
|
||||
// The config options should be added after the upgrade
|
||||
ASSERT_TRUE (!!tree.get_optional_child ("tcp_client_timeout"));
|
||||
ASSERT_TRUE (!!tree.get_optional_child ("tcp_server_timeout"));
|
||||
ASSERT_TRUE (!!tree.get_optional_child ("pow_sleep_interval"));
|
||||
ASSERT_TRUE (!!tree.get_optional_child ("external_address"));
|
||||
ASSERT_TRUE (!!tree.get_optional_child ("external_port"));
|
||||
|
||||
ASSERT_TRUE (upgraded);
|
||||
auto version (tree.get<std::string> ("version"));
|
||||
|
@ -727,22 +731,30 @@ TEST (node_config, v17_values)
|
|||
tree.put ("tcp_client_timeout", 1);
|
||||
tree.put ("tcp_server_timeout", 0);
|
||||
tree.put ("pow_sleep_interval", 0);
|
||||
tree.put ("external_address", "::1");
|
||||
tree.put ("external_port", 0);
|
||||
config.deserialize_json (upgraded, tree);
|
||||
ASSERT_FALSE (upgraded);
|
||||
ASSERT_EQ (config.tcp_client_timeout.count (), 1);
|
||||
ASSERT_EQ (config.tcp_server_timeout.count (), 0);
|
||||
ASSERT_EQ (config.pow_sleep_interval.count (), 0);
|
||||
ASSERT_EQ (config.external_address, boost::asio::ip::address_v6::from_string ("::1"));
|
||||
ASSERT_EQ (config.external_port, 0);
|
||||
|
||||
// Check config is correct with other values
|
||||
tree.put ("tcp_client_timeout", std::numeric_limits<unsigned long>::max () - 100);
|
||||
tree.put ("tcp_server_timeout", std::numeric_limits<unsigned>::max ());
|
||||
tree.put ("pow_sleep_interval", std::numeric_limits<unsigned long>::max () - 100);
|
||||
tree.put ("external_address", "::ffff:192.168.1.1");
|
||||
tree.put ("external_port", std::numeric_limits<uint16_t>::max () - 1);
|
||||
upgraded = false;
|
||||
config.deserialize_json (upgraded, tree);
|
||||
ASSERT_FALSE (upgraded);
|
||||
ASSERT_EQ (config.tcp_client_timeout.count (), std::numeric_limits<unsigned long>::max () - 100);
|
||||
ASSERT_EQ (config.tcp_server_timeout.count (), std::numeric_limits<unsigned>::max ());
|
||||
ASSERT_EQ (config.pow_sleep_interval.count (), std::numeric_limits<unsigned long>::max () - 100);
|
||||
ASSERT_EQ (config.external_address, boost::asio::ip::address_v6::from_string ("::ffff:192.168.1.1"));
|
||||
ASSERT_EQ (config.external_port, std::numeric_limits<uint16_t>::max () - 1);
|
||||
}
|
||||
|
||||
// Regression test to ensure that deserializing includes changes node via get_required_child
|
||||
|
|
|
@ -39,7 +39,6 @@ void nano::add_node_options (boost::program_options::options_description & descr
|
|||
("data_path", boost::program_options::value<std::string> (), "Use the supplied path as the data directory")
|
||||
("network", boost::program_options::value<std::string> (), "Use the supplied network (live, beta or test)")
|
||||
("clear_send_ids", "Remove all send IDs from the database (dangerous: not intended for production use)")
|
||||
("delete_node_id", "Delete the node ID in the database")
|
||||
("online_weight_clear", "Clear online weight history records")
|
||||
("peer_clear", "Clear online peers database dump")
|
||||
("unchecked_clear", "Clear unchecked blocks")
|
||||
|
@ -168,11 +167,6 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
auto transaction (node.node->store.tx_begin_write ());
|
||||
node.node->store.unchecked_clear (transaction);
|
||||
}
|
||||
if (vm.count ("delete_node_id"))
|
||||
{
|
||||
auto transaction (node.node->store.tx_begin_write ());
|
||||
node.node->store.delete_node_id (transaction);
|
||||
}
|
||||
if (vm.count ("clear_send_ids"))
|
||||
{
|
||||
auto transaction (node.node->wallets.tx_begin_write ());
|
||||
|
@ -234,11 +228,6 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
auto transaction (node.node->store.tx_begin_write ());
|
||||
node.node->store.unchecked_clear (transaction);
|
||||
}
|
||||
if (vm.count ("delete_node_id"))
|
||||
{
|
||||
auto transaction (node.node->store.tx_begin_write ());
|
||||
node.node->store.delete_node_id (transaction);
|
||||
}
|
||||
if (vm.count ("clear_send_ids"))
|
||||
{
|
||||
auto transaction (node.node->wallets.tx_begin_write ());
|
||||
|
@ -287,14 +276,6 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
node.node->store.unchecked_clear (transaction);
|
||||
std::cout << "Unchecked blocks deleted" << std::endl;
|
||||
}
|
||||
else if (vm.count ("delete_node_id"))
|
||||
{
|
||||
boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as<std::string> ()) : nano::working_path ();
|
||||
inactive_node node (data_path);
|
||||
auto transaction (node.node->store.tx_begin_write ());
|
||||
node.node->store.delete_node_id (transaction);
|
||||
std::cout << "Deleted Node ID" << std::endl;
|
||||
}
|
||||
else if (vm.count ("clear_send_ids"))
|
||||
{
|
||||
boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as<std::string> ()) : nano::working_path ();
|
||||
|
|
|
@ -877,34 +877,6 @@ int nano::mdb_store::version_get (nano::transaction const & transaction_a) const
|
|||
return result;
|
||||
}
|
||||
|
||||
nano::raw_key nano::mdb_store::get_node_id (nano::transaction const & transaction_a) const
|
||||
{
|
||||
nano::uint256_union node_id_mdb_key (3);
|
||||
nano::raw_key node_id;
|
||||
nano::mdb_val value;
|
||||
auto error (mdb_get (env.tx (transaction_a), meta, nano::mdb_val (node_id_mdb_key), value));
|
||||
if (!error)
|
||||
{
|
||||
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (value.data ()), value.size ());
|
||||
error = nano::try_read (stream, node_id.data);
|
||||
assert (!error);
|
||||
}
|
||||
if (error)
|
||||
{
|
||||
nano::random_pool::generate_block (node_id.data.bytes.data (), node_id.data.bytes.size ());
|
||||
error = mdb_put (env.tx (transaction_a), meta, nano::mdb_val (node_id_mdb_key), nano::mdb_val (node_id.data), 0);
|
||||
}
|
||||
assert (!error);
|
||||
return node_id;
|
||||
}
|
||||
|
||||
void nano::mdb_store::delete_node_id (nano::transaction const & transaction_a)
|
||||
{
|
||||
nano::uint256_union node_id_mdb_key (3);
|
||||
auto error (mdb_del (env.tx (transaction_a), meta, nano::mdb_val (node_id_mdb_key), nullptr));
|
||||
assert (!error || error == MDB_NOTFOUND);
|
||||
}
|
||||
|
||||
void nano::mdb_store::peer_put (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a)
|
||||
{
|
||||
nano::mdb_val zero (0);
|
||||
|
@ -1271,6 +1243,10 @@ void nano::mdb_store::upgrade_v13_to_v14 (nano::transaction const & transaction_
|
|||
}
|
||||
|
||||
logging.logger.always_log (boost::str (boost::format ("Completed confirmation height upgrade")));
|
||||
|
||||
nano::uint256_union node_id_mdb_key (3);
|
||||
auto error (mdb_del (env.tx (transaction_a), meta, nano::mdb_val (node_id_mdb_key), nullptr));
|
||||
release_assert (!error || error == MDB_NOTFOUND);
|
||||
}
|
||||
|
||||
void nano::mdb_store::clear (MDB_dbi db_a)
|
||||
|
|
|
@ -255,12 +255,6 @@ public:
|
|||
void version_put (nano::transaction const &, int) override;
|
||||
int version_get (nano::transaction const &) const override;
|
||||
|
||||
// Requires a write transaction
|
||||
nano::raw_key get_node_id (nano::transaction const &) const override;
|
||||
|
||||
/** Deletes the node ID from the store */
|
||||
void delete_node_id (nano::transaction const &) override;
|
||||
|
||||
void peer_put (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override;
|
||||
bool peer_exists (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const override;
|
||||
void peer_del (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override;
|
||||
|
|
|
@ -103,6 +103,23 @@ void nano::network::send_keepalive (nano::transport::channel const & channel_a)
|
|||
channel_a.send (message);
|
||||
}
|
||||
|
||||
void nano::network::send_keepalive_self (nano::transport::channel const & channel_a)
|
||||
{
|
||||
nano::keepalive message;
|
||||
udp_channels.random_fill (message.peers);
|
||||
if (node.config.external_address != boost::asio::ip::address_v6{} && node.config.external_port != 0)
|
||||
{
|
||||
message.peers[0] = nano::endpoint (node.config.external_address, node.config.external_port);
|
||||
}
|
||||
else
|
||||
{
|
||||
message.peers[0] = nano::endpoint (boost::asio::ip::address_v6{}, endpoint ().port ());
|
||||
message.peers[1] = node.port_mapping.external_address ();
|
||||
message.peers[2] = nano::endpoint (boost::asio::ip::address_v6{}, node.port_mapping.external_address ().port ()); // If UPnP reported wrong external IP address
|
||||
}
|
||||
channel_a.send (message);
|
||||
}
|
||||
|
||||
void nano::node::keepalive (std::string const & address_a, uint16_t port_a)
|
||||
{
|
||||
auto node_l (shared_from_this ());
|
||||
|
@ -538,11 +555,16 @@ void nano::network::merge_peers (std::array<nano::endpoint, 8> const & peers_a)
|
|||
{
|
||||
for (auto i (peers_a.begin ()), j (peers_a.end ()); i != j; ++i)
|
||||
{
|
||||
if (!udp_channels.reachout (*i, node.config.allow_local_peers))
|
||||
{
|
||||
nano::transport::channel_udp channel (node.network.udp_channels, *i);
|
||||
send_keepalive (channel);
|
||||
}
|
||||
merge_peer (*i);
|
||||
}
|
||||
}
|
||||
|
||||
void nano::network::merge_peer (nano::endpoint const & peer_a)
|
||||
{
|
||||
if (!udp_channels.reachout (peer_a, node.config.allow_local_peers))
|
||||
{
|
||||
nano::transport::channel_udp channel (node.network.udp_channels, peer_a);
|
||||
send_keepalive (channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1227,7 +1249,7 @@ startup_time (std::chrono::steady_clock::now ())
|
|||
std::exit (1);
|
||||
}
|
||||
|
||||
node_id = nano::keypair (store.get_node_id (transaction));
|
||||
node_id = nano::keypair ();
|
||||
logger.always_log ("Node ID: ", node_id.pub.to_account ());
|
||||
}
|
||||
|
||||
|
@ -1567,7 +1589,10 @@ void nano::node::start ()
|
|||
this_l->bootstrap_wallet ();
|
||||
});
|
||||
}
|
||||
port_mapping.start ();
|
||||
if (config.external_address != boost::asio::ip::address_v6{} && config.external_port != 0)
|
||||
{
|
||||
port_mapping.start ();
|
||||
}
|
||||
}
|
||||
|
||||
void nano::node::stop ()
|
||||
|
|
|
@ -334,7 +334,9 @@ public:
|
|||
}
|
||||
void flood_block_batch (std::deque<std::shared_ptr<nano::block>>, unsigned = broadcast_interval_ms);
|
||||
void merge_peers (std::array<nano::endpoint, 8> const &);
|
||||
void merge_peer (nano::endpoint const &);
|
||||
void send_keepalive (nano::transport::channel const &);
|
||||
void send_keepalive_self (nano::transport::channel const &);
|
||||
void send_node_id_handshake (nano::endpoint const &, boost::optional<nano::uint256_union> const & query, boost::optional<nano::uint256_union> const & respond_to);
|
||||
void broadcast_confirm_req (std::shared_ptr<nano::block>);
|
||||
void broadcast_confirm_req_base (std::shared_ptr<nano::block>, std::shared_ptr<std::vector<std::shared_ptr<nano::transport::channel>>>, unsigned, bool = false);
|
||||
|
|
|
@ -115,6 +115,8 @@ nano::error nano::node_config::serialize_json (nano::jsonconfig & json) const
|
|||
json.put ("tcp_client_timeout", tcp_client_timeout.count ());
|
||||
json.put ("tcp_server_timeout", tcp_server_timeout.count ());
|
||||
json.put ("pow_sleep_interval", pow_sleep_interval.count ());
|
||||
json.put ("external_address", external_address.to_string ());
|
||||
json.put ("external_port", external_port);
|
||||
nano::jsonconfig websocket_l;
|
||||
websocket_config.serialize_json (websocket_l);
|
||||
json.put_child ("websocket", websocket_l);
|
||||
|
@ -248,6 +250,8 @@ bool nano::node_config::upgrade_json (unsigned version_a, nano::jsonconfig & jso
|
|||
json.put ("tcp_client_timeout", tcp_client_timeout.count ());
|
||||
json.put ("tcp_server_timeout", tcp_server_timeout.count ());
|
||||
json.put (pow_sleep_interval_key, pow_sleep_interval.count ());
|
||||
json.put ("external_address", external_address.to_string ());
|
||||
json.put ("external_port", external_port);
|
||||
upgraded = true;
|
||||
}
|
||||
case 17:
|
||||
|
@ -382,6 +386,8 @@ nano::error nano::node_config::deserialize_json (bool & upgraded_a, nano::jsonco
|
|||
json.get<bool> ("enable_voting", enable_voting);
|
||||
json.get<bool> ("allow_local_peers", allow_local_peers);
|
||||
json.get<unsigned> (signature_checker_threads_key, signature_checker_threads);
|
||||
json.get<boost::asio::ip::address_v6> ("external_address", external_address);
|
||||
json.get<uint16_t> ("external_port", external_port);
|
||||
|
||||
auto pow_sleep_interval_l (pow_sleep_interval.count ());
|
||||
json.get (pow_sleep_interval_key, pow_sleep_interval_l);
|
||||
|
|
|
@ -55,6 +55,8 @@ public:
|
|||
nano::ipc::ipc_config ipc_config;
|
||||
nano::uint256_union epoch_block_link;
|
||||
nano::account epoch_block_signer;
|
||||
boost::asio::ip::address_v6 external_address{ boost::asio::ip::address_v6{} };
|
||||
uint16_t external_port{ 0 };
|
||||
std::chrono::milliseconds block_processor_batch_max_time{ std::chrono::milliseconds (5000) };
|
||||
std::chrono::seconds unchecked_cutoff_time{ std::chrono::seconds (4 * 60 * 60) }; // 4 hours
|
||||
std::chrono::seconds tcp_client_timeout{ std::chrono::seconds (5) };
|
||||
|
|
|
@ -48,6 +48,20 @@ void nano::port_mapping::refresh_devices ()
|
|||
}
|
||||
}
|
||||
|
||||
nano::endpoint nano::port_mapping::external_address ()
|
||||
{
|
||||
nano::endpoint result (boost::asio::ip::address_v6{}, 0);
|
||||
std::lock_guard<std::mutex> lock (mutex);
|
||||
for (auto & protocol : protocols)
|
||||
{
|
||||
if (protocol.external_port != 0)
|
||||
{
|
||||
result = nano::endpoint (protocol.external_address, protocol.external_port);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void nano::port_mapping::refresh_mapping ()
|
||||
{
|
||||
if (!network_params.network.is_test_network ())
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
void start ();
|
||||
void stop ();
|
||||
void refresh_devices ();
|
||||
nano::endpoint external_address ();
|
||||
|
||||
private:
|
||||
/** Add port mappings for the node port (not RPC). Refresh when the lease ends. */
|
||||
|
|
|
@ -298,6 +298,21 @@ bool nano::transport::udp_channels::reserved_address (nano::endpoint const & end
|
|||
return result;
|
||||
}
|
||||
|
||||
void nano::transport::udp_channels::clean_node_id (nano::endpoint const & endpoint_a, nano::account const & node_id_a)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock (mutex);
|
||||
auto existing (channels.get<node_id_tag> ().equal_range (node_id_a));
|
||||
for (auto & record : boost::make_iterator_range (existing))
|
||||
{
|
||||
// Remove duplicate node ID for same IP address
|
||||
if (record.endpoint ().address () == endpoint_a.address () && record.endpoint ().port () != endpoint_a.port ())
|
||||
{
|
||||
channels.get<endpoint_tag> ().erase (record.endpoint ());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nano::endpoint nano::transport::udp_channels::tcp_peer ()
|
||||
{
|
||||
nano::endpoint result (boost::asio::ip::address_v6::any (), 0);
|
||||
|
@ -404,7 +419,22 @@ public:
|
|||
auto cookie (node.network.udp_channels.assign_syn_cookie (endpoint));
|
||||
if (cookie)
|
||||
{
|
||||
// New connection
|
||||
node.network.send_node_id_handshake (endpoint, *cookie, boost::none);
|
||||
auto channel (node.network.udp_channels.channel (endpoint));
|
||||
if (channel)
|
||||
{
|
||||
node.network.send_keepalive_self (*channel);
|
||||
}
|
||||
}
|
||||
// Check for special node port data
|
||||
for (auto & peer : message_a.peers)
|
||||
{
|
||||
if (peer.address () == boost::asio::ip::address_v6{} && peer.port () != 0)
|
||||
{
|
||||
nano::endpoint new_endpoint (endpoint.address (), peer.port ());
|
||||
node.network.merge_peer (new_endpoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
message (message_a);
|
||||
|
@ -457,6 +487,7 @@ public:
|
|||
validated_response = true;
|
||||
if (message_a.response->first != node.node_id.pub)
|
||||
{
|
||||
node.network.udp_channels.clean_node_id (endpoint, message_a.response->first);
|
||||
auto channel (node.network.udp_channels.insert (endpoint, message_a.header.version_using));
|
||||
if (channel)
|
||||
{
|
||||
|
|
|
@ -48,6 +48,7 @@ namespace transport
|
|||
std::unordered_set<std::shared_ptr<nano::transport::channel_udp>> random_set (size_t) const;
|
||||
void store_all (nano::node &);
|
||||
bool reserved_address (nano::endpoint const &, bool = false);
|
||||
void clean_node_id (nano::endpoint const &, nano::account const &);
|
||||
// Get the next peer for attempting a tcp connection
|
||||
nano::endpoint tcp_peer ();
|
||||
void receive ();
|
||||
|
@ -98,6 +99,9 @@ namespace transport
|
|||
class last_tcp_attempt_tag
|
||||
{
|
||||
};
|
||||
class node_id_tag
|
||||
{
|
||||
};
|
||||
class channel_udp_wrapper final
|
||||
{
|
||||
public:
|
||||
|
@ -118,6 +122,17 @@ namespace transport
|
|||
{
|
||||
return endpoint ().address ();
|
||||
}
|
||||
nano::account node_id () const
|
||||
{
|
||||
if (channel->node_id.is_initialized ())
|
||||
{
|
||||
return channel->node_id.get ();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
class endpoint_attempt final
|
||||
{
|
||||
|
@ -138,6 +153,7 @@ namespace transport
|
|||
boost::multi_index::random_access<boost::multi_index::tag<random_access_tag>>,
|
||||
boost::multi_index::ordered_non_unique<boost::multi_index::tag<last_tcp_attempt_tag>, boost::multi_index::const_mem_fun<channel_udp_wrapper, std::chrono::steady_clock::time_point, &channel_udp_wrapper::last_tcp_attempt>>,
|
||||
boost::multi_index::hashed_unique<boost::multi_index::tag<endpoint_tag>, boost::multi_index::const_mem_fun<channel_udp_wrapper, nano::endpoint, &channel_udp_wrapper::endpoint>>,
|
||||
boost::multi_index::hashed_non_unique<boost::multi_index::tag<node_id_tag>, boost::multi_index::const_mem_fun<channel_udp_wrapper, nano::account, &channel_udp_wrapper::node_id>>,
|
||||
boost::multi_index::ordered_non_unique<boost::multi_index::tag<last_packet_received_tag>, boost::multi_index::const_mem_fun<channel_udp_wrapper, std::chrono::steady_clock::time_point, &channel_udp_wrapper::last_packet_received>>,
|
||||
boost::multi_index::ordered_non_unique<boost::multi_index::tag<ip_address_tag>, boost::multi_index::const_mem_fun<channel_udp_wrapper, boost::asio::ip::address, &channel_udp_wrapper::ip_address>>>>
|
||||
channels;
|
||||
|
|
|
@ -2254,13 +2254,7 @@ void nano::rpc_handler::node_id ()
|
|||
*/
|
||||
void nano::rpc_handler::node_id_delete ()
|
||||
{
|
||||
rpc_control_impl ();
|
||||
if (!ec)
|
||||
{
|
||||
auto transaction (node.store.tx_begin_write ());
|
||||
node.store.delete_node_id (transaction);
|
||||
response_l.put ("deleted", "1");
|
||||
}
|
||||
response_l.put ("deprecated", "1");
|
||||
response_errors ();
|
||||
}
|
||||
|
||||
|
@ -2333,7 +2327,7 @@ void nano::rpc_handler::peers ()
|
|||
{
|
||||
boost::property_tree::ptree pending_tree;
|
||||
pending_tree.put ("protocol_version", std::to_string (channel->network_version));
|
||||
if ((*i)->node_id.is_initialized ())
|
||||
if (channel->node_id.is_initialized ())
|
||||
{
|
||||
pending_tree.put ("node_id", channel->node_id.get ().to_account ());
|
||||
}
|
||||
|
|
|
@ -4765,35 +4765,8 @@ TEST (rpc, node_id)
|
|||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (200, response.status);
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
nano::keypair node_id (system.nodes[0]->store.get_node_id (transaction));
|
||||
ASSERT_EQ (node_id.prv.data.to_string (), response.json.get<std::string> ("private"));
|
||||
ASSERT_EQ (node_id.pub.to_account (), response.json.get<std::string> ("as_account"));
|
||||
}
|
||||
|
||||
TEST (rpc, node_id_delete)
|
||||
{
|
||||
nano::system system (24000, 1);
|
||||
nano::rpc rpc (system.io_ctx, *system.nodes[0], nano::rpc_config (true));
|
||||
rpc.start ();
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
nano::keypair node_id (system.nodes[0]->store.get_node_id (transaction));
|
||||
ASSERT_EQ (node_id.pub.to_string (), system.nodes[0]->node_id.pub.to_string ());
|
||||
}
|
||||
boost::property_tree::ptree request;
|
||||
request.put ("action", "node_id_delete");
|
||||
test_response response (request, rpc, system.io_ctx);
|
||||
system.deadline_set (5s);
|
||||
while (response.status == 0)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (200, response.status);
|
||||
ASSERT_EQ ("1", response.json.get<std::string> ("deleted"));
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
nano::keypair node_id (system.nodes[0]->store.get_node_id (transaction));
|
||||
ASSERT_NE (node_id.pub.to_string (), system.nodes[0]->node_id.pub.to_string ());
|
||||
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"));
|
||||
}
|
||||
|
||||
TEST (rpc, stats_clear)
|
||||
|
|
|
@ -311,12 +311,6 @@ public:
|
|||
|
||||
virtual uint64_t block_account_height (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0;
|
||||
|
||||
// Requires a write transaction
|
||||
virtual nano::raw_key get_node_id (nano::transaction const &) const = 0;
|
||||
|
||||
/** Deletes the node ID from the store */
|
||||
virtual void delete_node_id (nano::transaction const &) = 0;
|
||||
|
||||
/** Start read-write transaction */
|
||||
virtual nano::transaction tx_begin_write () = 0;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue