Pulling network_constants reference through rpc_config rather than initializing statically.
This commit is contained in:
parent
cad65ee436
commit
210f725e16
9 changed files with 34 additions and 30 deletions
|
@ -88,8 +88,8 @@ TEST (toml, rpc_config_deserialize_defaults)
|
|||
|
||||
nano::tomlconfig t;
|
||||
t.read (ss);
|
||||
nano::rpc_config conf;
|
||||
nano::rpc_config defaults;
|
||||
nano::rpc_config conf{ nano::dev::network_params.network };
|
||||
nano::rpc_config defaults{ nano::dev::network_params.network };
|
||||
conf.deserialize_toml (t);
|
||||
|
||||
ASSERT_FALSE (t.get_error ()) << t.get_error ().get_message ();
|
||||
|
@ -717,8 +717,8 @@ TEST (toml, rpc_config_deserialize_no_defaults)
|
|||
|
||||
nano::tomlconfig toml;
|
||||
toml.read (ss);
|
||||
nano::rpc_config conf;
|
||||
nano::rpc_config defaults;
|
||||
nano::rpc_config conf{ nano::dev::network_params.network };
|
||||
nano::rpc_config defaults{ nano::dev::network_params.network };
|
||||
conf.deserialize_toml (toml);
|
||||
|
||||
ASSERT_FALSE (toml.get_error ()) << toml.get_error ().get_message ();
|
||||
|
@ -752,8 +752,8 @@ TEST (toml, rpc_config_no_required)
|
|||
|
||||
nano::tomlconfig toml;
|
||||
toml.read (ss);
|
||||
nano::rpc_config conf;
|
||||
nano::rpc_config defaults;
|
||||
nano::rpc_config conf{ nano::dev::network_params.network };
|
||||
nano::rpc_config defaults{ nano::dev::network_params.network };
|
||||
conf.deserialize_toml (toml);
|
||||
|
||||
ASSERT_FALSE (toml.get_error ()) << toml.get_error ().get_message ();
|
||||
|
|
|
@ -54,15 +54,17 @@ nano::error nano::rpc_secure_config::deserialize_toml (nano::tomlconfig & toml)
|
|||
return toml.get_error ();
|
||||
}
|
||||
|
||||
nano::rpc_config::rpc_config () :
|
||||
address (boost::asio::ip::address_v6::loopback ().to_string ())
|
||||
nano::rpc_config::rpc_config (nano::network_constants & network_constants) :
|
||||
rpc_process{ network_constants },
|
||||
address{ boost::asio::ip::address_v6::loopback ().to_string () }
|
||||
{
|
||||
}
|
||||
|
||||
nano::rpc_config::rpc_config (uint16_t port_a, bool enable_control_a) :
|
||||
address (boost::asio::ip::address_v6::loopback ().to_string ()),
|
||||
port (port_a),
|
||||
enable_control (enable_control_a)
|
||||
nano::rpc_config::rpc_config (nano::network_constants & network_constants, uint16_t port_a, bool enable_control_a) :
|
||||
rpc_process{ network_constants },
|
||||
address{ boost::asio::ip::address_v6::loopback ().to_string () },
|
||||
port{ port_a },
|
||||
enable_control{ enable_control_a }
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -183,8 +185,9 @@ nano::error nano::rpc_config::deserialize_toml (nano::tomlconfig & toml)
|
|||
return toml.get_error ();
|
||||
}
|
||||
|
||||
nano::rpc_process_config::rpc_process_config () :
|
||||
ipc_address (boost::asio::ip::address_v6::loopback ().to_string ())
|
||||
nano::rpc_process_config::rpc_process_config (nano::network_constants & network_constants) :
|
||||
network_constants{ network_constants },
|
||||
ipc_address{ boost::asio::ip::address_v6::loopback ().to_string () }
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -206,7 +209,7 @@ nano::error read_rpc_config_toml (boost::filesystem::path const & data_path_a, n
|
|||
else
|
||||
{
|
||||
// Migrate
|
||||
nano::rpc_config config_json_l;
|
||||
nano::rpc_config config_json_l{ config_a.rpc_process.network_constants };
|
||||
error = read_and_update_rpc_config (data_path_a, config_json_l);
|
||||
|
||||
if (!error)
|
||||
|
@ -215,7 +218,7 @@ nano::error read_rpc_config_toml (boost::filesystem::path const & data_path_a, n
|
|||
config_json_l.serialize_toml (toml_l);
|
||||
|
||||
// Only write out non-default values
|
||||
nano::rpc_config config_defaults_l;
|
||||
nano::rpc_config config_defaults_l{ config_a.rpc_process.network_constants };
|
||||
nano::tomlconfig toml_defaults_l;
|
||||
config_defaults_l.serialize_toml (toml_defaults_l);
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ public:
|
|||
class rpc_process_config final
|
||||
{
|
||||
public:
|
||||
rpc_process_config ();
|
||||
nano::network_constants network_constants;
|
||||
rpc_process_config (nano::network_constants & network_constants);
|
||||
nano::network_constants & network_constants;
|
||||
unsigned io_threads{ (4 < std::thread::hardware_concurrency ()) ? std::thread::hardware_concurrency () : 4 };
|
||||
std::string ipc_address;
|
||||
uint16_t ipc_port{ network_constants.default_ipc_port };
|
||||
|
@ -69,8 +69,8 @@ public:
|
|||
class rpc_config final
|
||||
{
|
||||
public:
|
||||
rpc_config ();
|
||||
explicit rpc_config (uint16_t, bool);
|
||||
explicit rpc_config (nano::network_constants & network_constants);
|
||||
explicit rpc_config (nano::network_constants & network_constants, uint16_t, bool);
|
||||
nano::error serialize_json (nano::jsonconfig &) const;
|
||||
nano::error deserialize_json (bool & upgraded_a, nano::jsonconfig &);
|
||||
nano::error serialize_toml (nano::tomlconfig &) const;
|
||||
|
|
|
@ -56,7 +56,7 @@ void write_config_files (boost::filesystem::path const & data_path, int index)
|
|||
daemon_config.serialize_toml (toml);
|
||||
toml.write (nano::get_node_toml_config_path (data_path));
|
||||
|
||||
nano::rpc_config rpc_config;
|
||||
nano::rpc_config rpc_config{ daemon_config.node.network_params.network };
|
||||
rpc_config.port = rpc_port_start + index;
|
||||
rpc_config.enable_control = true;
|
||||
rpc_config.rpc_process.ipc_port = ipc_port_start + index;
|
||||
|
|
|
@ -119,7 +119,7 @@ void nano_daemon::daemon::run (boost::filesystem::path const & data_path, nano::
|
|||
if (!config.rpc.child_process.enable)
|
||||
{
|
||||
// Launch rpc in-process
|
||||
nano::rpc_config rpc_config;
|
||||
nano::rpc_config rpc_config{ config.node.network_params.network };
|
||||
auto error = nano::read_rpc_config_toml (data_path, rpc_config, flags.rpc_config_overrides);
|
||||
if (error)
|
||||
{
|
||||
|
|
|
@ -39,8 +39,9 @@ void run (boost::filesystem::path const & data_path, std::vector<std::string> co
|
|||
boost::system::error_code error_chmod;
|
||||
nano::set_secure_perm_directory (data_path, error_chmod);
|
||||
std::unique_ptr<nano::thread_runner> runner;
|
||||
nano::network_constants network;
|
||||
|
||||
nano::rpc_config rpc_config;
|
||||
nano::rpc_config rpc_config{ network };
|
||||
auto error = nano::read_rpc_config_toml (data_path, rpc_config, config_overrides);
|
||||
if (!error)
|
||||
{
|
||||
|
|
|
@ -167,7 +167,7 @@ int run_wallet (QApplication & application, int argc, char * const * argv, boost
|
|||
if (!config.rpc.child_process.enable)
|
||||
{
|
||||
// Launch rpc in-process
|
||||
nano::rpc_config rpc_config;
|
||||
nano::rpc_config rpc_config{ config.node.network_params.network };
|
||||
auto error = nano::read_rpc_config_toml (data_path, rpc_config, flags.rpc_config_overrides);
|
||||
if (error)
|
||||
{
|
||||
|
|
|
@ -664,7 +664,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
else if (type == "rpc")
|
||||
{
|
||||
valid_type = true;
|
||||
nano::rpc_config config;
|
||||
nano::rpc_config config{ nano::dev::network_params.network };
|
||||
config.serialize_toml (toml);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -199,7 +199,7 @@ std::tuple<std::shared_ptr<nano::rpc>, std::unique_ptr<rpc_context>> add_rpc (na
|
|||
auto scoped_thread_name_io (std::make_unique<scoped_io_thread_name_change> ());
|
||||
auto node_rpc_config (std::make_unique<nano::node_rpc_config> ());
|
||||
auto ipc_server (std::make_unique<nano::ipc::ipc_server> (*node_a, *node_rpc_config));
|
||||
nano::rpc_config rpc_config (nano::get_available_port (), true);
|
||||
nano::rpc_config rpc_config (node_a->network_params.network, nano::get_available_port (), true);
|
||||
rpc_config.rpc_process.ipc_port = node_a->config.ipc_config.transport_tcp.port;
|
||||
auto ipc_rpc_processor (std::make_unique<nano::ipc_rpc_processor> (system.io_ctx, rpc_config));
|
||||
auto rpc (std::make_shared<nano::rpc> (system.io_ctx, rpc_config, *ipc_rpc_processor));
|
||||
|
@ -5499,7 +5499,7 @@ TEST (rpc, simultaneous_calls)
|
|||
nano::thread_runner runner (system.io_ctx, node->config.io_threads);
|
||||
nano::node_rpc_config node_rpc_config;
|
||||
nano::ipc::ipc_server ipc_server (*node, node_rpc_config);
|
||||
nano::rpc_config rpc_config (nano::get_available_port (), true);
|
||||
nano::rpc_config rpc_config{ nano::dev::network_params.network, nano::get_available_port (), true };
|
||||
rpc_config.rpc_process.ipc_port = node->config.ipc_config.transport_tcp.port;
|
||||
rpc_config.rpc_process.num_ipc_connections = 8;
|
||||
nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config);
|
||||
|
@ -5553,7 +5553,7 @@ TEST (rpc, in_process)
|
|||
nano::system system;
|
||||
auto node = add_ipc_enabled_node (system);
|
||||
scoped_io_thread_name_change scoped_thread_name_io;
|
||||
nano::rpc_config rpc_config (nano::get_available_port (), true);
|
||||
nano::rpc_config rpc_config (nano::dev::network_params.network, nano::get_available_port (), true);
|
||||
rpc_config.rpc_process.ipc_port = node->config.ipc_config.transport_tcp.port;
|
||||
nano::node_rpc_config node_rpc_config;
|
||||
nano::ipc::ipc_server ipc_server (*node, node_rpc_config);
|
||||
|
@ -5572,7 +5572,7 @@ TEST (rpc, in_process)
|
|||
|
||||
TEST (rpc_config, serialization)
|
||||
{
|
||||
nano::rpc_config config1;
|
||||
nano::rpc_config config1{ nano::dev::network_params.network };
|
||||
config1.address = boost::asio::ip::address_v6::any ().to_string ();
|
||||
config1.port = 10;
|
||||
config1.enable_control = true;
|
||||
|
@ -5583,7 +5583,7 @@ TEST (rpc_config, serialization)
|
|||
config1.rpc_process.num_ipc_connections = 99;
|
||||
nano::jsonconfig tree;
|
||||
config1.serialize_json (tree);
|
||||
nano::rpc_config config2;
|
||||
nano::rpc_config config2{ nano::dev::network_params.network };
|
||||
ASSERT_NE (config2.address, config1.address);
|
||||
ASSERT_NE (config2.port, config1.port);
|
||||
ASSERT_NE (config2.enable_control, config1.enable_control);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue