--diagnostics CLI option to check & update config.json file (#1733)

* --diagonistics now creates config.json file

Formatting

See if this fixes the nano_wallet failure

Actually add it...

Separate config files

Formatting

Formatting

* Formatting
This commit is contained in:
Wesley Shillingford 2019-02-22 09:52:26 +00:00 committed by GitHub
commit b78941aec1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 412 additions and 334 deletions

View file

@ -5,7 +5,6 @@ add_executable (core_test
interface.cpp
ipc.cpp
conflicts.cpp
daemon.cpp
entry.cpp
gap_cache.cpp
ledger.cpp

View file

@ -1,5 +1,6 @@
#pragma once
#include <boost/filesystem.hpp>
#include <chrono>
#include <cstddef>
@ -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";
}
}

View file

@ -1,125 +1,21 @@
#include <boost/property_tree/json_parser.hpp>
#include <fstream>
#include <iostream>
#include <nano/lib/jsonconfig.hpp>
#include <nano/lib/utility.hpp>
#include <nano/nano_node/daemon.hpp>
#include <nano/node/daemonconfig.hpp>
#include <nano/node/ipc.hpp>
#include <nano/node/working.hpp>
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<int> ("version", version_l);
upgraded_a |= upgrade_json (version_l, json);
json.get_optional<bool> ("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<bool> ("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<bool> ("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<nano::thread_runner> 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);

View file

@ -1,7 +1,9 @@
#include <nano/lib/errors.hpp>
#include <nano/node/node.hpp>
#include <nano/node/rpc.hpp>
#include <boost/filesystem.hpp>
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;
}
};
}

BIN
nano/nano_wallet/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -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

View file

@ -1,6 +1,7 @@
#include <nano/lib/interface.h>
#include <nano/node/cli.hpp>
#include <nano/node/common.hpp>
#include <nano/node/daemonconfig.hpp>
#include <nano/node/node.hpp>
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 ();

116
nano/node/daemonconfig.cpp Normal file
View file

@ -0,0 +1,116 @@
#include <nano/node/daemonconfig.hpp>
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<int> ("version", version_l);
upgraded_a |= upgrade_json (version_l, json);
json.get_optional<bool> ("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<bool> ("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<bool> ("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;
}
}

View file

@ -0,0 +1,33 @@
#pragma once
#include <nano/lib/errors.hpp>
#include <nano/node/node.hpp>
#include <nano/node/rpc.hpp>
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);
}

View file

@ -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<long> ("io_threads", transport_tcp.io_threads, -1);
tcp_l->get<bool> ("enable", transport_tcp.enabled);
tcp_l->get<uint16_t> ("port", transport_tcp.port);
tcp_l->get<size_t> ("io_timeout", transport_tcp.io_timeout);
}
auto domain_l (json.get_optional_child ("local"));
if (domain_l)
{
domain_l->get_optional<long> ("io_threads", transport_domain.io_threads, -1);
domain_l->get<bool> ("enable", transport_domain.enabled);
domain_l->get<std::string> ("path", transport_domain.path);
domain_l->get<size_t> ("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

View file

@ -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
{

50
nano/node/ipcconfig.cpp Normal file
View file

@ -0,0 +1,50 @@
#include <nano/lib/jsonconfig.hpp>
#include <nano/node/ipcconfig.hpp>
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<long> ("io_threads", transport_tcp.io_threads, -1);
tcp_l->get<bool> ("enable", transport_tcp.enabled);
tcp_l->get<uint16_t> ("port", transport_tcp.port);
tcp_l->get<size_t> ("io_timeout", transport_tcp.io_timeout);
}
auto domain_l (json.get_optional_child ("local"));
if (domain_l)
{
domain_l->get_optional<long> ("io_threads", transport_domain.io_threads, -1);
domain_l->get<bool> ("enable", transport_domain.enabled);
domain_l->get<std::string> ("path", transport_domain.path);
domain_l->get<size_t> ("io_timeout", transport_domain.io_timeout);
}
return json.get_error ();
}

51
nano/node/ipcconfig.hpp Normal file
View file

@ -0,0 +1,51 @@
#pragma once
#include <nano/lib/errors.hpp>
#include <string>
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;
};
}
}

View file

@ -4,7 +4,7 @@
#include <nano/lib/errors.hpp>
#include <nano/lib/jsonconfig.hpp>
#include <nano/lib/numbers.hpp>
#include <nano/node/ipc.hpp>
#include <nano/node/ipcconfig.hpp>
#include <nano/node/logging.hpp>
#include <nano/node/stats.hpp>
#include <vector>

View file

@ -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<bool> ("enable", enable);
json.get_required<bool> ("verbose_logging", verbose_logging);
json.get_required<std::string> ("server_key_passphrase", server_key_passphrase);
json.get_required<std::string> ("server_cert_path", server_cert_path);
json.get_required<std::string> ("server_key_path", server_key_path);
json.get_required<std::string> ("server_dh_path", server_dh_path);
json.get_required<std::string> ("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<boost::asio::ip::address_v6> ("address", address);
json.get_optional<uint16_t> ("port", port);
json.get_optional<bool> ("enable_control", enable_control);
json.get_optional<uint64_t> ("frontier_request_limit", frontier_request_limit);
json.get_optional<uint64_t> ("chain_request_limit", chain_request_limit);
json.get_optional<uint8_t> ("max_json_depth", max_json_depth);
json.get_optional<bool> ("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),

View file

@ -8,6 +8,7 @@
#include <nano/lib/blocks.hpp>
#include <nano/lib/errors.hpp>
#include <nano/lib/jsonconfig.hpp>
#include <nano/node/rpcconfig.hpp>
#include <nano/secure/blockstore.hpp>
#include <nano/secure/utility.hpp>
#include <unordered_map>
@ -16,44 +17,6 @@ namespace nano
{
void error_response (std::function<void(boost::property_tree::ptree const &)> 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<nano::rpc_connection>
{

View file

@ -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:

74
nano/node/rpcconfig.cpp Normal file
View file

@ -0,0 +1,74 @@
#include <nano/lib/config.hpp>
#include <nano/lib/jsonconfig.hpp>
#include <nano/node/rpcconfig.hpp>
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<bool> ("enable", enable);
json.get_required<bool> ("verbose_logging", verbose_logging);
json.get_required<std::string> ("server_key_passphrase", server_key_passphrase);
json.get_required<std::string> ("server_cert_path", server_cert_path);
json.get_required<std::string> ("server_key_path", server_key_path);
json.get_required<std::string> ("server_dh_path", server_dh_path);
json.get_required<std::string> ("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<boost::asio::ip::address_v6> ("address", address);
json.get_optional<uint16_t> ("port", port);
json.get_optional<bool> ("enable_control", enable_control);
json.get_optional<uint64_t> ("frontier_request_limit", frontier_request_limit);
json.get_optional<uint64_t> ("chain_request_limit", chain_request_limit);
json.get_optional<uint8_t> ("max_json_depth", max_json_depth);
json.get_optional<bool> ("enable_sign_hash", enable_sign_hash);
return json.get_error ();
}

50
nano/node/rpcconfig.hpp Normal file
View file

@ -0,0 +1,50 @@
#pragma once
#include <boost/asio.hpp>
#include <nano/lib/errors.hpp>
#include <string>
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;
};
}