diff options
Diffstat (limited to 'src/rpc')
-rw-r--r-- | src/rpc/core_rpc_server.cpp | 33 | ||||
-rw-r--r-- | src/rpc/core_rpc_server.h | 7 | ||||
-rw-r--r-- | src/rpc/core_rpc_server_commands_defs.h | 6 |
3 files changed, 35 insertions, 11 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 64a9c86d5..3a3d9f664 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -68,7 +68,9 @@ namespace cryptonote void core_rpc_server::init_options(boost::program_options::options_description& desc) { command_line::add_arg(desc, arg_rpc_bind_port); + command_line::add_arg(desc, arg_rpc_restricted_bind_port); command_line::add_arg(desc, arg_testnet_rpc_bind_port); + command_line::add_arg(desc, arg_testnet_rpc_restricted_bind_port); command_line::add_arg(desc, arg_restricted_rpc); cryptonote::rpc_args::init_options(desc); } @@ -83,21 +85,21 @@ namespace cryptonote //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::init( const boost::program_options::variables_map& vm + , const bool restricted + , const bool testnet + , const std::string& port ) { - m_testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on); + m_restricted = restricted; + m_testnet = testnet; m_net_server.set_threads_prefix("RPC"); - auto p2p_bind_arg = m_testnet ? arg_testnet_rpc_bind_port : arg_rpc_bind_port; - auto rpc_config = cryptonote::rpc_args::process(vm); if (!rpc_config) return false; - m_restricted = command_line::get_arg(vm, arg_restricted_rpc); - boost::optional<epee::net_utils::http::login> http_login{}; - std::string port = command_line::get_arg(vm, p2p_bind_arg); + if (rpc_config->login) http_login.emplace(std::move(rpc_config->login->username), std::move(rpc_config->login->password).password()); @@ -149,6 +151,7 @@ namespace cryptonote res.block_size_limit = m_core.get_blockchain_storage().get_current_cumulative_blocksize_limit(); res.status = CORE_RPC_STATUS_OK; res.start_time = (uint64_t)m_core.get_start_time(); + res.free_space = m_restricted ? std::numeric_limits<uint64_t>::max() : m_core.get_free_space(); return true; } //------------------------------------------------------------------------------------------------------------------------------ @@ -1328,6 +1331,7 @@ namespace cryptonote res.block_size_limit = m_core.get_blockchain_storage().get_current_cumulative_blocksize_limit(); res.status = CORE_RPC_STATUS_OK; res.start_time = (uint64_t)m_core.get_start_time(); + res.free_space = m_restricted ? std::numeric_limits<uint64_t>::max() : m_core.get_free_space(); return true; } //------------------------------------------------------------------------------------------------------------------------------ @@ -1745,12 +1749,13 @@ namespace cryptonote res.peers.push_back({c}); const cryptonote::block_queue &block_queue = m_p2p.get_payload_object().get_block_queue(); block_queue.foreach([&](const cryptonote::block_queue::span &span) { + const std::string span_connection_id = epee::string_tools::pod_to_hex(span.connection_id); uint32_t speed = (uint32_t)(100.0f * block_queue.get_speed(span.connection_id) + 0.5f); std::string address = ""; for (const auto &c: m_p2p.get_payload_object().get_connections()) - if (c.connection_id == span.connection_id) + if (c.connection_id == span_connection_id) address = c.address; - res.spans.push_back({span.start_block_height, span.nblocks, span.connection_id, (uint32_t)(span.rate + 0.5f), speed, span.size, address}); + res.spans.push_back({span.start_block_height, span.nblocks, span_connection_id, (uint32_t)(span.rate + 0.5f), speed, span.size, address}); return true; }); @@ -1780,12 +1785,24 @@ namespace cryptonote , std::to_string(config::RPC_DEFAULT_PORT) }; + const command_line::arg_descriptor<std::string> core_rpc_server::arg_rpc_restricted_bind_port = { + "rpc-restricted-bind-port" + , "Port for restricted RPC server" + , "" + }; + const command_line::arg_descriptor<std::string> core_rpc_server::arg_testnet_rpc_bind_port = { "testnet-rpc-bind-port" , "Port for testnet RPC server" , std::to_string(config::testnet::RPC_DEFAULT_PORT) }; + const command_line::arg_descriptor<std::string> core_rpc_server::arg_testnet_rpc_restricted_bind_port = { + "testnet-rpc-restricted-bind-port" + , "Port for testnet restricted RPC server" + , "" + }; + const command_line::arg_descriptor<bool> core_rpc_server::arg_restricted_rpc = { "restricted-rpc" , "Restrict RPC to view only commands and do not return privacy sensitive data in RPC calls" diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index 7f252258c..bf4371a4e 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -53,7 +53,9 @@ namespace cryptonote public: static const command_line::arg_descriptor<std::string> arg_rpc_bind_port; + static const command_line::arg_descriptor<std::string> arg_rpc_restricted_bind_port; static const command_line::arg_descriptor<std::string> arg_testnet_rpc_bind_port; + static const command_line::arg_descriptor<std::string> arg_testnet_rpc_restricted_bind_port; static const command_line::arg_descriptor<bool> arg_restricted_rpc; typedef epee::net_utils::connection_context_base connection_context; @@ -65,7 +67,10 @@ namespace cryptonote static void init_options(boost::program_options::options_description& desc); bool init( - const boost::program_options::variables_map& vm + const boost::program_options::variables_map& vm, + const bool restricted, + const bool testnet, + const std::string& port ); bool is_testnet() const { return m_testnet; } diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 15b4b503a..58a6ce9e1 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -927,6 +927,7 @@ namespace cryptonote uint64_t cumulative_difficulty; uint64_t block_size_limit; uint64_t start_time; + uint64_t free_space; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(status) @@ -947,6 +948,7 @@ namespace cryptonote KV_SERIALIZE(cumulative_difficulty) KV_SERIALIZE(block_size_limit) KV_SERIALIZE(start_time) + KV_SERIALIZE(free_space) END_KV_SERIALIZE_MAP() }; }; @@ -2075,7 +2077,7 @@ namespace cryptonote { uint64_t start_block_height; uint64_t nblocks; - boost::uuids::uuid connection_id; + std::string connection_id; uint32_t rate; uint32_t speed; uint64_t size; @@ -2084,7 +2086,7 @@ namespace cryptonote BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(start_block_height) KV_SERIALIZE(nblocks) - KV_SERIALIZE_VAL_POD_AS_BLOB(connection_id) + KV_SERIALIZE(connection_id) KV_SERIALIZE(rate) KV_SERIALIZE(speed) KV_SERIALIZE(size) |