Skip to content

Commit

Permalink
Move inactive_node and node_wrapper into their own files
Browse files Browse the repository at this point in the history
  • Loading branch information
dsiganos committed Apr 8, 2024
1 parent 6b89da2 commit 14f4d38
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 96 deletions.
1 change: 1 addition & 0 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <nano/node/active_transactions.hpp>
#include <nano/node/confirming_set.hpp>
#include <nano/node/election.hpp>
#include <nano/node/inactive_node.hpp>
#include <nano/node/local_vote_history.hpp>
#include <nano/node/make_store.hpp>
#include <nano/node/scheduler/component.hpp>
Expand Down
1 change: 1 addition & 0 deletions nano/core_test/socket.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <nano/boost/asio/ip/address_v6.hpp>
#include <nano/boost/asio/ip/network_v6.hpp>
#include <nano/lib/thread_runner.hpp>
#include <nano/node/inactive_node.hpp>
#include <nano/node/transport/socket.hpp>
#include <nano/node/transport/tcp_listener.hpp>
#include <nano/test_common/system.hpp>
Expand Down
1 change: 1 addition & 0 deletions nano/core_test/wallets.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <nano/lib/blocks.hpp>
#include <nano/node/active_transactions.hpp>
#include <nano/node/election.hpp>
#include <nano/node/inactive_node.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/store/versioning.hpp>
#include <nano/test_common/system.hpp>
Expand Down
1 change: 1 addition & 0 deletions nano/nano_node/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <nano/node/cli.hpp>
#include <nano/node/confirming_set.hpp>
#include <nano/node/daemonconfig.hpp>
#include <nano/node/inactive_node.hpp>
#include <nano/node/ipc/ipc_server.hpp>
#include <nano/node/json_handler.hpp>
#include <nano/node/node.hpp>
Expand Down
4 changes: 4 additions & 0 deletions nano/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ add_library(
node_observers.cpp
node_rpc_config.hpp
node_rpc_config.cpp
node_wrapper.hpp
node_wrapper.cpp
inactive_node.hpp
inactive_node.cpp
node.hpp
node.cpp
online_reps.hpp
Expand Down
1 change: 1 addition & 0 deletions nano/node/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <nano/node/cli.hpp>
#include <nano/node/common.hpp>
#include <nano/node/daemonconfig.hpp>
#include <nano/node/inactive_node.hpp>
#include <nano/node/node.hpp>
#include <nano/secure/ledger.hpp>

Expand Down
29 changes: 29 additions & 0 deletions nano/node/inactive_node.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <nano/node/active_transactions.hpp>
#include <nano/node/inactive_node.hpp>
#include <nano/node/node.hpp>

nano::inactive_node::inactive_node (std::filesystem::path const & path_a, std::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a) :
node_wrapper (path_a, config_path_a, node_flags_a),
node (node_wrapper.node)
{
node_wrapper.node->active.stop ();
}

nano::inactive_node::inactive_node (std::filesystem::path const & path_a, nano::node_flags const & node_flags_a) :
inactive_node (path_a, path_a, node_flags_a)
{
}

nano::node_flags const & nano::inactive_node_flag_defaults ()
{
static nano::node_flags node_flags;
node_flags.inactive_node = true;
node_flags.read_only = true;
node_flags.generate_cache.reps = false;
node_flags.generate_cache.cemented_count = false;
node_flags.generate_cache.unchecked_count = false;
node_flags.generate_cache.account_count = false;
node_flags.disable_bootstrap_listener = true;
node_flags.disable_tcp_realtime = true;
return node_flags;
}
27 changes: 27 additions & 0 deletions nano/node/inactive_node.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <nano/node/node_wrapper.hpp>

#include <boost/program_options/variables_map.hpp>

#include <filesystem>

namespace nano
{

class node;
class node_flags;

class inactive_node final
{
public:
inactive_node (std::filesystem::path const & path_a, nano::node_flags const & node_flags_a);
inactive_node (std::filesystem::path const & path_a, std::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a);

nano::node_wrapper node_wrapper;
std::shared_ptr<nano::node> node;
};

std::unique_ptr<nano::inactive_node> default_inactive_node (std::filesystem::path const &, boost::program_options::variables_map const &);

} // namespace nano
74 changes: 1 addition & 73 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1376,76 +1376,4 @@ std::string nano::node::make_logger_identifier (const nano::keypair & node_id)
{
// Node identifier consists of first 10 characters of node id
return node_id.pub.to_node_id ().substr (0, 10);
}

/*
* node_wrapper
*/

nano::node_wrapper::node_wrapper (std::filesystem::path const & path_a, std::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a) :
network_params{ nano::network_constants::active_network },
io_context (std::make_shared<boost::asio::io_context> ()),
work{ network_params.network, 1 }
{
/*
* @warning May throw a filesystem exception
*/
std::filesystem::create_directories (path_a);

boost::system::error_code error_chmod;
nano::set_secure_perm_directory (path_a, error_chmod);

nano::daemon_config daemon_config{ path_a, network_params };
auto error = nano::read_node_config_toml (config_path_a, daemon_config, node_flags_a.config_overrides);
if (error)
{
std::cerr << "Error deserializing config file";
if (!node_flags_a.config_overrides.empty ())
{
std::cerr << " or --config option";
}
std::cerr << "\n"
<< error.get_message () << std::endl;
std::exit (1);
}

auto & node_config = daemon_config.node;
node_config.peering_port = 24000;

node = std::make_shared<nano::node> (io_context, path_a, node_config, work, node_flags_a);
}

nano::node_wrapper::~node_wrapper ()
{
node->stop ();
}

/*
* inactive_node
*/

nano::inactive_node::inactive_node (std::filesystem::path const & path_a, std::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a) :
node_wrapper (path_a, config_path_a, node_flags_a),
node (node_wrapper.node)
{
node_wrapper.node->active.stop ();
}

nano::inactive_node::inactive_node (std::filesystem::path const & path_a, nano::node_flags const & node_flags_a) :
inactive_node (path_a, path_a, node_flags_a)
{
}

nano::node_flags const & nano::inactive_node_flag_defaults ()
{
static nano::node_flags node_flags;
node_flags.inactive_node = true;
node_flags.read_only = true;
node_flags.generate_cache.reps = false;
node_flags.generate_cache.cemented_count = false;
node_flags.generate_cache.unchecked_count = false;
node_flags.generate_cache.account_count = false;
node_flags.disable_bootstrap_listener = true;
node_flags.disable_tcp_realtime = true;
return node_flags;
}
}
24 changes: 1 addition & 23 deletions nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,26 +236,4 @@ std::unique_ptr<container_info_component> collect_container_info (node & node, s

nano::node_flags const & inactive_node_flag_defaults ();

class node_wrapper final
{
public:
node_wrapper (std::filesystem::path const & path_a, std::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a);
~node_wrapper ();

nano::network_params network_params;
std::shared_ptr<boost::asio::io_context> io_context;
nano::work_pool work;
std::shared_ptr<nano::node> node;
};

class inactive_node final
{
public:
inactive_node (std::filesystem::path const & path_a, nano::node_flags const & node_flags_a);
inactive_node (std::filesystem::path const & path_a, std::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a);

nano::node_wrapper node_wrapper;
std::shared_ptr<nano::node> node;
};
std::unique_ptr<nano::inactive_node> default_inactive_node (std::filesystem::path const &, boost::program_options::variables_map const &);
}
}
41 changes: 41 additions & 0 deletions nano/node/node_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <nano/node/daemonconfig.hpp>
#include <nano/node/node.hpp>
#include <nano/node/node_wrapper.hpp>

nano::node_wrapper::node_wrapper (std::filesystem::path const & path_a, std::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a) :
network_params{ nano::network_constants::active_network },
io_context (std::make_shared<boost::asio::io_context> ()),
work{ network_params.network, 1 }
{
/*
* @warning May throw a filesystem exception
*/
std::filesystem::create_directories (path_a);

boost::system::error_code error_chmod;
nano::set_secure_perm_directory (path_a, error_chmod);

nano::daemon_config daemon_config{ path_a, network_params };
auto error = nano::read_node_config_toml (config_path_a, daemon_config, node_flags_a.config_overrides);
if (error)
{
std::cerr << "Error deserializing config file";
if (!node_flags_a.config_overrides.empty ())
{
std::cerr << " or --config option";
}
std::cerr << "\n"
<< error.get_message () << std::endl;
std::exit (1);
}

auto & node_config = daemon_config.node;
node_config.peering_port = 24000;

node = std::make_shared<nano::node> (io_context, path_a, node_config, work, node_flags_a);
}

nano::node_wrapper::~node_wrapper ()
{
node->stop ();
}
28 changes: 28 additions & 0 deletions nano/node/node_wrapper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <nano/lib/work.hpp>
#include <nano/secure/common.hpp>

#include <boost/asio/io_context.hpp>

#include <filesystem>

namespace nano
{

class node;
class node_flags;

class node_wrapper final
{
public:
node_wrapper (std::filesystem::path const & path_a, std::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a);
~node_wrapper ();

nano::network_params network_params;
std::shared_ptr<boost::asio::io_context> io_context;
nano::work_pool work;
std::shared_ptr<nano::node> node;
};

}

0 comments on commit 14f4d38

Please sign in to comment.