diff --git a/nano/core_test/CMakeLists.txt b/nano/core_test/CMakeLists.txt index 125d1bac..5e73f135 100644 --- a/nano/core_test/CMakeLists.txt +++ b/nano/core_test/CMakeLists.txt @@ -5,7 +5,6 @@ add_executable (core_test interface.cpp ipc.cpp conflicts.cpp - daemon.cpp entry.cpp gap_cache.cpp ledger.cpp diff --git a/nano/lib/config.hpp b/nano/lib/config.hpp index 6a9d520b..cc69edb6 100644 --- a/nano/lib/config.hpp +++ b/nano/lib/config.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -27,4 +28,9 @@ bool constexpr is_beta_network = nano_network == nano_networks::nano_beta_networ bool constexpr is_test_network = nano_network == nano_networks::nano_test_network; std::chrono::milliseconds const transaction_timeout = std::chrono::milliseconds (1000); + +inline boost::filesystem::path get_config_path (boost::filesystem::path const & data_path) +{ + return data_path / "config.json"; +} } diff --git a/nano/nano_node/daemon.cpp b/nano/nano_node/daemon.cpp index fbecdb04..7efc05b4 100644 --- a/nano/nano_node/daemon.cpp +++ b/nano/nano_node/daemon.cpp @@ -1,125 +1,21 @@ #include #include #include -#include #include #include +#include #include #include -nano_daemon::daemon_config::daemon_config () : -rpc_enable (false), -opencl_enable (false) -{ -} - -nano::error nano_daemon::daemon_config::serialize_json (nano::jsonconfig & json) -{ - json.put ("version", json_version ()); - json.put ("rpc_enable", rpc_enable); - - nano::jsonconfig rpc_l; - rpc.serialize_json (rpc_l); - json.put_child ("rpc", rpc_l); - - nano::jsonconfig node_l; - node.serialize_json (node_l); - nano::jsonconfig node (node_l); - json.put_child ("node", node); - - json.put ("opencl_enable", opencl_enable); - nano::jsonconfig opencl_l; - opencl.serialize_json (opencl_l); - json.put_child ("opencl", opencl_l); - return json.get_error (); -} - -nano::error nano_daemon::daemon_config::deserialize_json (bool & upgraded_a, nano::jsonconfig & json) -{ - try - { - if (!json.empty ()) - { - int version_l; - json.get_optional ("version", version_l); - upgraded_a |= upgrade_json (version_l, json); - - json.get_optional ("rpc_enable", rpc_enable); - auto rpc_l (json.get_required_child ("rpc")); - - if (!rpc.deserialize_json (rpc_l)) - { - auto node_l (json.get_required_child ("node")); - if (!json.get_error ()) - { - node.deserialize_json (upgraded_a, node_l); - } - } - if (!json.get_error ()) - { - json.get_required ("opencl_enable", opencl_enable); - auto opencl_l (json.get_required_child ("opencl")); - if (!json.get_error ()) - { - opencl.deserialize_json (opencl_l); - } - } - } - else - { - upgraded_a = true; - serialize_json (json); - } - } - catch (std::runtime_error const & ex) - { - json.get_error () = ex; - } - return json.get_error (); -} - -bool nano_daemon::daemon_config::upgrade_json (unsigned version_a, nano::jsonconfig & json) -{ - json.put ("version", json_version ()); - auto upgraded_l (false); - switch (version_a) - { - case 1: - { - bool opencl_enable_l; - json.get_optional ("opencl_enable", opencl_enable_l); - if (!opencl_enable_l) - { - json.put ("opencl_enable", false); - } - auto opencl_l (json.get_optional_child ("opencl")); - if (!opencl_l) - { - nano::jsonconfig opencl_l; - opencl.serialize_json (opencl_l); - json.put_child ("opencl", opencl_l); - } - upgraded_l = true; - } - case 2: - break; - default: - throw std::runtime_error ("Unknown daemon_config version"); - } - return upgraded_l; -} - void nano_daemon::daemon::run (boost::filesystem::path const & data_path, nano::node_flags const & flags) { - boost::system::error_code error_chmod; boost::filesystem::create_directories (data_path); - nano_daemon::daemon_config config; + boost::system::error_code error_chmod; nano::set_secure_perm_directory (data_path, error_chmod); - auto config_path ((data_path / "config.json")); std::unique_ptr runner; - nano::jsonconfig json; - auto error (json.read_and_update (config, config_path)); - nano::set_secure_perm_file (config_path, error_chmod); + nano::daemon_config config; + auto error = nano::read_and_update_daemon_config (data_path, config); + if (!error) { config.node.logging.init (data_path); diff --git a/nano/nano_node/daemon.hpp b/nano/nano_node/daemon.hpp index 5ee10fb9..4301f7c3 100644 --- a/nano/nano_node/daemon.hpp +++ b/nano/nano_node/daemon.hpp @@ -1,7 +1,9 @@ -#include -#include -#include +#include +namespace nano +{ +class node_flags; +} namespace nano_daemon { class daemon @@ -9,26 +11,4 @@ class daemon public: void run (boost::filesystem::path const &, nano::node_flags const & flags); }; -class daemon_config -{ -public: - daemon_config (); - nano::error deserialize_json (bool &, nano::jsonconfig &); - nano::error serialize_json (nano::jsonconfig &); - /** - * Returns true if an upgrade occurred - * @param version The version to upgrade to. - * @param config Configuration to upgrade. - */ - bool upgrade_json (unsigned version, nano::jsonconfig & config); - bool rpc_enable; - nano::rpc_config rpc; - nano::node_config node; - bool opencl_enable; - nano::opencl_config opencl; - int json_version () const - { - return 2; - } -}; } diff --git a/nano/nano_wallet/.DS_Store b/nano/nano_wallet/.DS_Store new file mode 100644 index 00000000..4f64277e Binary files /dev/null and b/nano/nano_wallet/.DS_Store differ diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index c565e060..2c7d1036 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -25,8 +25,12 @@ add_library (node cli.cpp common.cpp common.hpp + daemonconfig.hpp + daemonconfig.cpp ipc.hpp ipc.cpp + ipcconfig.hpp + ipcconfig.cpp lmdb.cpp lmdb.hpp logging.cpp @@ -43,6 +47,8 @@ add_library (node portmapping.cpp rpc.hpp rpc.cpp + rpcconfig.hpp + rpcconfig.cpp testing.hpp testing.cpp signatures.hpp diff --git a/nano/node/cli.cpp b/nano/node/cli.cpp index 8ea8d622..7f3d3c4e 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include std::string nano::error_cli_messages::message (int ev) const @@ -307,6 +308,17 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map else if (vm.count ("diagnostics")) { inactive_node node (data_path); + + // Check/upgrade the config.json file. + { + nano::daemon_config config; + auto error = nano::read_and_update_daemon_config (data_path, config); + if (error) + { + std::cerr << "Error deserializing config: " << error.get_message () << std::endl; + } + } + std::cout << "Testing hash function" << std::endl; nano::raw_key key; key.data.clear (); diff --git a/nano/node/daemonconfig.cpp b/nano/node/daemonconfig.cpp new file mode 100644 index 00000000..a4da60fb --- /dev/null +++ b/nano/node/daemonconfig.cpp @@ -0,0 +1,116 @@ +#include + +nano::daemon_config::daemon_config () : +rpc_enable (false), +opencl_enable (false) +{ +} + +nano::error nano::daemon_config::serialize_json (nano::jsonconfig & json) +{ + json.put ("version", json_version ()); + json.put ("rpc_enable", rpc_enable); + + nano::jsonconfig rpc_l; + rpc.serialize_json (rpc_l); + json.put_child ("rpc", rpc_l); + + nano::jsonconfig node_l; + node.serialize_json (node_l); + nano::jsonconfig node (node_l); + json.put_child ("node", node); + + json.put ("opencl_enable", opencl_enable); + nano::jsonconfig opencl_l; + opencl.serialize_json (opencl_l); + json.put_child ("opencl", opencl_l); + return json.get_error (); +} + +nano::error nano::daemon_config::deserialize_json (bool & upgraded_a, nano::jsonconfig & json) +{ + try + { + if (!json.empty ()) + { + int version_l; + json.get_optional ("version", version_l); + upgraded_a |= upgrade_json (version_l, json); + + json.get_optional ("rpc_enable", rpc_enable); + auto rpc_l (json.get_required_child ("rpc")); + + if (!rpc.deserialize_json (rpc_l)) + { + auto node_l (json.get_required_child ("node")); + if (!json.get_error ()) + { + node.deserialize_json (upgraded_a, node_l); + } + } + if (!json.get_error ()) + { + json.get_required ("opencl_enable", opencl_enable); + auto opencl_l (json.get_required_child ("opencl")); + if (!json.get_error ()) + { + opencl.deserialize_json (opencl_l); + } + } + } + else + { + upgraded_a = true; + serialize_json (json); + } + } + catch (std::runtime_error const & ex) + { + json.get_error () = ex; + } + return json.get_error (); +} + +bool nano::daemon_config::upgrade_json (unsigned version_a, nano::jsonconfig & json) +{ + json.put ("version", json_version ()); + auto upgraded_l (false); + switch (version_a) + { + case 1: + { + bool opencl_enable_l; + json.get_optional ("opencl_enable", opencl_enable_l); + if (!opencl_enable_l) + { + json.put ("opencl_enable", false); + } + auto opencl_l (json.get_optional_child ("opencl")); + if (!opencl_l) + { + nano::jsonconfig opencl_l; + opencl.serialize_json (opencl_l); + json.put_child ("opencl", opencl_l); + } + upgraded_l = true; + } + case 2: + break; + default: + throw std::runtime_error ("Unknown daemon_config version"); + } + return upgraded_l; +} + +namespace nano +{ +nano::error read_and_update_daemon_config (boost::filesystem::path const & data_path, nano::daemon_config & config_a) +{ + boost::system::error_code error_chmod; + nano::jsonconfig json; + auto config_path = nano::get_config_path (data_path); + auto error (json.read_and_update (config_a, config_path)); + nano::set_secure_perm_file (config_path, error_chmod); + return error; +} +} diff --git a/nano/node/daemonconfig.hpp b/nano/node/daemonconfig.hpp new file mode 100644 index 00000000..8184f5e6 --- /dev/null +++ b/nano/node/daemonconfig.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include +#include +#include + +namespace nano +{ +class daemon_config +{ +public: + daemon_config (); + nano::error deserialize_json (bool &, nano::jsonconfig &); + nano::error serialize_json (nano::jsonconfig &); + /** + * Returns true if an upgrade occurred + * @param version The version to upgrade to. + * @param config Configuration to upgrade. + */ + bool upgrade_json (unsigned version, nano::jsonconfig & config); + bool rpc_enable; + nano::rpc_config rpc; + nano::node_config node; + bool opencl_enable; + nano::opencl_config opencl; + int json_version () const + { + return 2; + } +}; + +nano::error read_and_update_daemon_config (boost::filesystem::path const &, nano::daemon_config & config_a); +} diff --git a/nano/node/ipc.cpp b/nano/node/ipc.cpp index e24ec364..6dd40d66 100644 --- a/nano/node/ipc.cpp +++ b/nano/node/ipc.cpp @@ -38,53 +38,6 @@ enum preamble_offset reserved_2 = 3, }; } -nano::error nano::ipc::ipc_config::serialize_json (nano::jsonconfig & json) const -{ - nano::jsonconfig tcp_l; - // Only write out experimental config values if they're previously set explicitly in the config file - if (transport_tcp.io_threads >= 0) - { - tcp_l.put ("io_threads", transport_tcp.io_threads); - } - tcp_l.put ("enable", transport_tcp.enabled); - tcp_l.put ("port", transport_tcp.port); - tcp_l.put ("io_timeout", transport_tcp.io_timeout); - json.put_child ("tcp", tcp_l); - - nano::jsonconfig domain_l; - if (transport_domain.io_threads >= 0) - { - domain_l.put ("io_threads", transport_domain.io_threads); - } - domain_l.put ("enable", transport_domain.enabled); - domain_l.put ("path", transport_domain.path); - domain_l.put ("io_timeout", transport_domain.io_timeout); - json.put_child ("local", domain_l); - return json.get_error (); -} - -nano::error nano::ipc::ipc_config::deserialize_json (nano::jsonconfig & json) -{ - auto tcp_l (json.get_optional_child ("tcp")); - if (tcp_l) - { - tcp_l->get_optional ("io_threads", transport_tcp.io_threads, -1); - tcp_l->get ("enable", transport_tcp.enabled); - tcp_l->get ("port", transport_tcp.port); - tcp_l->get ("io_timeout", transport_tcp.io_timeout); - } - - auto domain_l (json.get_optional_child ("local")); - if (domain_l) - { - domain_l->get_optional ("io_threads", transport_domain.io_threads, -1); - domain_l->get ("enable", transport_domain.enabled); - domain_l->get ("path", transport_domain.path); - domain_l->get ("io_timeout", transport_domain.io_timeout); - } - - return json.get_error (); -} /** Abstract base type for sockets, implementing timer logic and a close operation */ class socket_base diff --git a/nano/node/ipc.hpp b/nano/node/ipc.hpp index ec4ae7ac..b9ae57a3 100644 --- a/nano/node/ipc.hpp +++ b/nano/node/ipc.hpp @@ -41,45 +41,6 @@ namespace ipc virtual ~transport () = default; }; - /** Base class for transport configurations */ - class ipc_config_transport - { - public: - virtual ~ipc_config_transport () = default; - bool enabled{ false }; - size_t io_timeout{ 15 }; - long io_threads{ -1 }; - }; - - /** Domain socket specific transport config */ - class ipc_config_domain_socket : public ipc_config_transport - { - public: - /** - * Default domain socket path for Unix systems. Once Boost supports Windows 10 usocks, - * this value will be conditional on OS. - */ - std::string path{ "/tmp/nano" }; - }; - - /** TCP specific transport config */ - class ipc_config_tcp_socket : public ipc_config_transport - { - public: - /** Listening port */ - uint16_t port{ 7077 }; - }; - - /** IPC configuration */ - class ipc_config - { - public: - nano::error deserialize_json (nano::jsonconfig & json_a); - nano::error serialize_json (nano::jsonconfig & json) const; - ipc_config_domain_socket transport_domain; - ipc_config_tcp_socket transport_tcp; - }; - /** The IPC server accepts connections on one or more configured transports */ class ipc_server { diff --git a/nano/node/ipcconfig.cpp b/nano/node/ipcconfig.cpp new file mode 100644 index 00000000..3f526ba0 --- /dev/null +++ b/nano/node/ipcconfig.cpp @@ -0,0 +1,50 @@ +#include +#include + +nano::error nano::ipc::ipc_config::serialize_json (nano::jsonconfig & json) const +{ + nano::jsonconfig tcp_l; + // Only write out experimental config values if they're previously set explicitly in the config file + if (transport_tcp.io_threads >= 0) + { + tcp_l.put ("io_threads", transport_tcp.io_threads); + } + tcp_l.put ("enable", transport_tcp.enabled); + tcp_l.put ("port", transport_tcp.port); + tcp_l.put ("io_timeout", transport_tcp.io_timeout); + json.put_child ("tcp", tcp_l); + + nano::jsonconfig domain_l; + if (transport_domain.io_threads >= 0) + { + domain_l.put ("io_threads", transport_domain.io_threads); + } + domain_l.put ("enable", transport_domain.enabled); + domain_l.put ("path", transport_domain.path); + domain_l.put ("io_timeout", transport_domain.io_timeout); + json.put_child ("local", domain_l); + return json.get_error (); +} + +nano::error nano::ipc::ipc_config::deserialize_json (nano::jsonconfig & json) +{ + auto tcp_l (json.get_optional_child ("tcp")); + if (tcp_l) + { + tcp_l->get_optional ("io_threads", transport_tcp.io_threads, -1); + tcp_l->get ("enable", transport_tcp.enabled); + tcp_l->get ("port", transport_tcp.port); + tcp_l->get ("io_timeout", transport_tcp.io_timeout); + } + + auto domain_l (json.get_optional_child ("local")); + if (domain_l) + { + domain_l->get_optional ("io_threads", transport_domain.io_threads, -1); + domain_l->get ("enable", transport_domain.enabled); + domain_l->get ("path", transport_domain.path); + domain_l->get ("io_timeout", transport_domain.io_timeout); + } + + return json.get_error (); +} diff --git a/nano/node/ipcconfig.hpp b/nano/node/ipcconfig.hpp new file mode 100644 index 00000000..1729975e --- /dev/null +++ b/nano/node/ipcconfig.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include +#include + +namespace nano +{ +class jsonconfig; + +namespace ipc +{ + /** Base class for transport configurations */ + class ipc_config_transport + { + public: + virtual ~ipc_config_transport () = default; + bool enabled{ false }; + size_t io_timeout{ 15 }; + long io_threads{ -1 }; + }; + + /** Domain socket specific transport config */ + class ipc_config_domain_socket : public ipc_config_transport + { + public: + /** + * Default domain socket path for Unix systems. Once Boost supports Windows 10 usocks, + * this value will be conditional on OS. + */ + std::string path{ "/tmp/nano" }; + }; + + /** TCP specific transport config */ + class ipc_config_tcp_socket : public ipc_config_transport + { + public: + /** Listening port */ + uint16_t port{ 7077 }; + }; + + /** IPC configuration */ + class ipc_config + { + public: + nano::error deserialize_json (nano::jsonconfig & json_a); + nano::error serialize_json (nano::jsonconfig & json) const; + ipc_config_domain_socket transport_domain; + ipc_config_tcp_socket transport_tcp; + }; +} +} diff --git a/nano/node/nodeconfig.hpp b/nano/node/nodeconfig.hpp index cbe34b60..91a25e41 100644 --- a/nano/node/nodeconfig.hpp +++ b/nano/node/nodeconfig.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/nano/node/rpc.cpp b/nano/node/rpc.cpp index 33b50e24..63c104f3 100644 --- a/nano/node/rpc.cpp +++ b/nano/node/rpc.cpp @@ -14,77 +14,6 @@ namespace void construct_json (nano::seq_con_info_component * component, boost::property_tree::ptree & parent); } -nano::rpc_secure_config::rpc_secure_config () : -enable (false), -verbose_logging (false) -{ -} - -nano::error nano::rpc_secure_config::serialize_json (nano::jsonconfig & json) const -{ - json.put ("enable", enable); - json.put ("verbose_logging", verbose_logging); - json.put ("server_key_passphrase", server_key_passphrase); - json.put ("server_cert_path", server_cert_path); - json.put ("server_key_path", server_key_path); - json.put ("server_dh_path", server_dh_path); - json.put ("client_certs_path", client_certs_path); - return json.get_error (); -} - -nano::error nano::rpc_secure_config::deserialize_json (nano::jsonconfig & json) -{ - json.get_required ("enable", enable); - json.get_required ("verbose_logging", verbose_logging); - json.get_required ("server_key_passphrase", server_key_passphrase); - json.get_required ("server_cert_path", server_cert_path); - json.get_required ("server_key_path", server_key_path); - json.get_required ("server_dh_path", server_dh_path); - json.get_required ("client_certs_path", client_certs_path); - return json.get_error (); -} - -nano::rpc_config::rpc_config (bool enable_control_a) : -address (boost::asio::ip::address_v6::loopback ()), -port (nano::rpc::rpc_port), -enable_control (enable_control_a), -frontier_request_limit (16384), -chain_request_limit (16384), -max_json_depth (20), -enable_sign_hash (false) -{ -} - -nano::error nano::rpc_config::serialize_json (nano::jsonconfig & json) const -{ - json.put ("address", address.to_string ()); - json.put ("port", port); - json.put ("enable_control", enable_control); - json.put ("frontier_request_limit", frontier_request_limit); - json.put ("chain_request_limit", chain_request_limit); - json.put ("max_json_depth", max_json_depth); - json.put ("enable_sign_hash", enable_sign_hash); - return json.get_error (); -} - -nano::error nano::rpc_config::deserialize_json (nano::jsonconfig & json) -{ - auto rpc_secure_l (json.get_optional_child ("secure")); - if (rpc_secure_l) - { - secure.deserialize_json (*rpc_secure_l); - } - - json.get_required ("address", address); - json.get_optional ("port", port); - json.get_optional ("enable_control", enable_control); - json.get_optional ("frontier_request_limit", frontier_request_limit); - json.get_optional ("chain_request_limit", chain_request_limit); - json.get_optional ("max_json_depth", max_json_depth); - json.get_optional ("enable_sign_hash", enable_sign_hash); - return json.get_error (); -} - nano::rpc::rpc (boost::asio::io_context & io_ctx_a, nano::node & node_a, nano::rpc_config const & config_a) : acceptor (io_ctx_a), config (config_a), diff --git a/nano/node/rpc.hpp b/nano/node/rpc.hpp index 518348c9..3b8b5f0e 100644 --- a/nano/node/rpc.hpp +++ b/nano/node/rpc.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -16,44 +17,6 @@ namespace nano { void error_response (std::function response_a, std::string const & message_a); class node; -/** Configuration options for RPC TLS */ -class rpc_secure_config -{ -public: - rpc_secure_config (); - nano::error serialize_json (nano::jsonconfig &) const; - nano::error deserialize_json (nano::jsonconfig &); - - /** If true, enable TLS */ - bool enable; - /** If true, log certificate verification details */ - bool verbose_logging; - /** Must be set if the private key PEM is password protected */ - std::string server_key_passphrase; - /** Path to certificate- or chain file. Must be PEM formatted. */ - std::string server_cert_path; - /** Path to private key file. Must be PEM formatted.*/ - std::string server_key_path; - /** Path to dhparam file */ - std::string server_dh_path; - /** Optional path to directory containing client certificates */ - std::string client_certs_path; -}; -class rpc_config -{ -public: - rpc_config (bool = false); - nano::error serialize_json (nano::jsonconfig &) const; - nano::error deserialize_json (nano::jsonconfig &); - boost::asio::ip::address_v6 address; - uint16_t port; - bool enable_control; - uint64_t frontier_request_limit; - uint64_t chain_request_limit; - rpc_secure_config secure; - uint8_t max_json_depth; - bool enable_sign_hash; -}; enum class payment_status { not_a_status, @@ -87,7 +50,6 @@ public: nano::rpc_config config; nano::node & node; bool on; - static uint16_t const rpc_port = nano::is_live_network ? 7076 : 55000; }; class rpc_connection : public std::enable_shared_from_this { diff --git a/nano/node/rpc_secure.cpp b/nano/node/rpc_secure.cpp index b764a102..86ecfd5d 100644 --- a/nano/node/rpc_secure.cpp +++ b/nano/node/rpc_secure.cpp @@ -190,16 +190,16 @@ void nano::rpc_connection_secure::read () this_l->prepare_head (version); this_l->res.set (boost::beast::http::field::allow, "POST, OPTIONS"); this_l->res.prepare_payload (); + // clang-format off boost::beast::http::async_write (this_l->stream, this_l->res, [this_l](boost::system::error_code const & ec, size_t bytes_transferred) { - // Perform the SSL shutdown this_l->stream.async_shutdown ( std::bind ( &nano::rpc_connection_secure::on_shutdown, this_l, std::placeholders::_1)); - }); + // clang-format on break; } default: diff --git a/nano/node/rpcconfig.cpp b/nano/node/rpcconfig.cpp new file mode 100644 index 00000000..7850860b --- /dev/null +++ b/nano/node/rpcconfig.cpp @@ -0,0 +1,74 @@ +#include +#include +#include + +nano::rpc_secure_config::rpc_secure_config () : +enable (false), +verbose_logging (false) +{ +} + +nano::error nano::rpc_secure_config::serialize_json (nano::jsonconfig & json) const +{ + json.put ("enable", enable); + json.put ("verbose_logging", verbose_logging); + json.put ("server_key_passphrase", server_key_passphrase); + json.put ("server_cert_path", server_cert_path); + json.put ("server_key_path", server_key_path); + json.put ("server_dh_path", server_dh_path); + json.put ("client_certs_path", client_certs_path); + return json.get_error (); +} + +nano::error nano::rpc_secure_config::deserialize_json (nano::jsonconfig & json) +{ + json.get_required ("enable", enable); + json.get_required ("verbose_logging", verbose_logging); + json.get_required ("server_key_passphrase", server_key_passphrase); + json.get_required ("server_cert_path", server_cert_path); + json.get_required ("server_key_path", server_key_path); + json.get_required ("server_dh_path", server_dh_path); + json.get_required ("client_certs_path", client_certs_path); + return json.get_error (); +} + +nano::rpc_config::rpc_config (bool enable_control_a) : +address (boost::asio::ip::address_v6::loopback ()), +port (nano::is_live_network ? 7076 : 55000), +enable_control (enable_control_a), +frontier_request_limit (16384), +chain_request_limit (16384), +max_json_depth (20), +enable_sign_hash (false) +{ +} + +nano::error nano::rpc_config::serialize_json (nano::jsonconfig & json) const +{ + json.put ("address", address.to_string ()); + json.put ("port", port); + json.put ("enable_control", enable_control); + json.put ("frontier_request_limit", frontier_request_limit); + json.put ("chain_request_limit", chain_request_limit); + json.put ("max_json_depth", max_json_depth); + json.put ("enable_sign_hash", enable_sign_hash); + return json.get_error (); +} + +nano::error nano::rpc_config::deserialize_json (nano::jsonconfig & json) +{ + auto rpc_secure_l (json.get_optional_child ("secure")); + if (rpc_secure_l) + { + secure.deserialize_json (*rpc_secure_l); + } + + json.get_required ("address", address); + json.get_optional ("port", port); + json.get_optional ("enable_control", enable_control); + json.get_optional ("frontier_request_limit", frontier_request_limit); + json.get_optional ("chain_request_limit", chain_request_limit); + json.get_optional ("max_json_depth", max_json_depth); + json.get_optional ("enable_sign_hash", enable_sign_hash); + return json.get_error (); +} diff --git a/nano/node/rpcconfig.hpp b/nano/node/rpcconfig.hpp new file mode 100644 index 00000000..4c31d081 --- /dev/null +++ b/nano/node/rpcconfig.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include + +namespace nano +{ +class jsonconfig; + +/** Configuration options for RPC TLS */ +class rpc_secure_config +{ +public: + rpc_secure_config (); + nano::error serialize_json (nano::jsonconfig &) const; + nano::error deserialize_json (nano::jsonconfig &); + + /** If true, enable TLS */ + bool enable; + /** If true, log certificate verification details */ + bool verbose_logging; + /** Must be set if the private key PEM is password protected */ + std::string server_key_passphrase; + /** Path to certificate- or chain file. Must be PEM formatted. */ + std::string server_cert_path; + /** Path to private key file. Must be PEM formatted.*/ + std::string server_key_path; + /** Path to dhparam file */ + std::string server_dh_path; + /** Optional path to directory containing client certificates */ + std::string client_certs_path; +}; + +class rpc_config +{ +public: + rpc_config (bool = false); + nano::error serialize_json (nano::jsonconfig &) const; + nano::error deserialize_json (nano::jsonconfig &); + boost::asio::ip::address_v6 address; + uint16_t port; + bool enable_control; + uint64_t frontier_request_limit; + uint64_t chain_request_limit; + rpc_secure_config secure; + uint8_t max_json_depth; + bool enable_sign_hash; +}; +}