Adding rpc bind address option.
This commit is contained in:
parent
b06360c1de
commit
0cbabbdab0
5 changed files with 26 additions and 15 deletions
|
@ -8,6 +8,7 @@
|
|||
rai_daemon::daemon_config::daemon_config () :
|
||||
peering_port (24000),
|
||||
rpc_enable (false),
|
||||
rpc_address (boost::asio::ip::address_v6::loopback ()),
|
||||
rpc_port (25000),
|
||||
rpc_enable_control (false)
|
||||
{
|
||||
|
@ -26,6 +27,7 @@ void rai_daemon::daemon_config::serialize (std::ostream & output_a)
|
|||
bootstrap_peers_l.push_back (std::make_pair ("", entry));
|
||||
}
|
||||
tree.add_child ("bootstrap_peers", bootstrap_peers_l);
|
||||
tree.put ("rpc_address", rpc_address.to_string ());
|
||||
tree.put ("rpc_port", std::to_string (rpc_port));
|
||||
tree.put ("rpc_enable", rpc_enable);
|
||||
tree.put ("rpc_enable_control", rpc_enable_control);
|
||||
|
@ -40,6 +42,7 @@ rai_daemon::daemon_config::daemon_config (bool & error_a, std::istream & input_a
|
|||
{
|
||||
boost::property_tree::read_json (input_a, tree);
|
||||
auto peering_port_l (tree.get <std::string> ("peering_port"));
|
||||
auto rpc_address_l (tree.get <std::string> ("rpc_address"));
|
||||
auto rpc_port_l (tree.get <std::string> ("rpc_port"));
|
||||
rpc_enable = tree.get <bool> ("rpc_enable");
|
||||
rpc_enable_control = tree.get <bool> ("rpc_enable_control");
|
||||
|
@ -59,6 +62,12 @@ rai_daemon::daemon_config::daemon_config (bool & error_a, std::istream & input_a
|
|||
{
|
||||
error_a = true;
|
||||
}
|
||||
boost::system::error_code ec;
|
||||
boost::asio::ip::address_v6::from_string (rpc_address_l, ec);
|
||||
if (ec)
|
||||
{
|
||||
error_a = true;
|
||||
}
|
||||
}
|
||||
catch (std::runtime_error const &)
|
||||
{
|
||||
|
@ -103,7 +112,7 @@ void rai_daemon::daemon::run ()
|
|||
{
|
||||
client->processor.connect_bootstrap (config.bootstrap_peers);
|
||||
client->start ();
|
||||
rai::rpc rpc (service, pool, config.rpc_port, *client, config.rpc_enable_control);
|
||||
rai::rpc rpc (service, pool, config.rpc_address, config.rpc_port, *client, config.rpc_enable_control);
|
||||
if (config.rpc_enable)
|
||||
{
|
||||
rpc.start ();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <rai/core/core.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/asio/ip/address_v6.hpp>
|
||||
|
||||
namespace rai_daemon
|
||||
{
|
||||
|
@ -19,6 +20,7 @@ namespace rai_daemon
|
|||
std::vector <std::string> bootstrap_peers;
|
||||
uint16_t peering_port;
|
||||
bool rpc_enable;
|
||||
boost::asio::ip::address_v6 rpc_address;
|
||||
uint16_t rpc_port;
|
||||
bool rpc_enable_control;
|
||||
};
|
||||
|
|
|
@ -1594,8 +1594,8 @@ void rai::confirm_req::serialize (rai::stream & stream_a)
|
|||
block->serialize (stream_a);
|
||||
}
|
||||
|
||||
rai::rpc::rpc (boost::shared_ptr <boost::asio::io_service> service_a, boost::shared_ptr <boost::network::utils::thread_pool> pool_a, uint16_t port_a, rai::client & client_a, bool enable_control_a) :
|
||||
server (decltype (server)::options (*this).address ("0.0.0.0").port (std::to_string (port_a)).io_service (service_a).thread_pool (pool_a)),
|
||||
rai::rpc::rpc (boost::shared_ptr <boost::asio::io_service> service_a, boost::shared_ptr <boost::network::utils::thread_pool> pool_a, boost::asio::ip::address_v6 const & address_a, uint16_t port_a, rai::client & client_a, bool enable_control_a) :
|
||||
server (decltype (server)::options (*this).address (address_a.to_string ()).port (std::to_string (port_a)).io_service (service_a).thread_pool (pool_a)),
|
||||
client (client_a),
|
||||
enable_control (enable_control_a)
|
||||
{
|
||||
|
|
|
@ -558,7 +558,7 @@ namespace rai {
|
|||
class rpc
|
||||
{
|
||||
public:
|
||||
rpc (boost::shared_ptr <boost::asio::io_service>, boost::shared_ptr <boost::network::utils::thread_pool>, uint16_t, rai::client &, bool);
|
||||
rpc (boost::shared_ptr <boost::asio::io_service>, boost::shared_ptr <boost::network::utils::thread_pool>, boost::asio::ip::address_v6 const &, uint16_t, rai::client &, bool);
|
||||
void start ();
|
||||
void stop ();
|
||||
boost::network::http::server <rai::rpc> server;
|
||||
|
|
|
@ -368,7 +368,7 @@ TEST (rpc, account_create)
|
|||
{
|
||||
rai::system system (24000, 1);
|
||||
auto pool (boost::make_shared <boost::network::utils::thread_pool> ());
|
||||
rai::rpc rpc (system.service, pool, 25000, *system.clients [0], true);
|
||||
rai::rpc rpc (system.service, pool, boost::asio::ip::address_v6::loopback (), 25000, *system.clients [0], true);
|
||||
boost::network::http::server <rai::rpc>::request request;
|
||||
boost::network::http::server <rai::rpc>::response response;
|
||||
request.method = "POST";
|
||||
|
@ -392,7 +392,7 @@ TEST (rpc, account_balance)
|
|||
{
|
||||
rai::system system (24000, 1);
|
||||
auto pool (boost::make_shared <boost::network::utils::thread_pool> ());
|
||||
rai::rpc rpc (system.service, pool, 25000, *system.clients [0], true);
|
||||
rai::rpc rpc (system.service, pool, boost::asio::ip::address_v6::loopback (), 25000, *system.clients [0], true);
|
||||
std::string account;
|
||||
rai::test_genesis_key.pub.encode_base58check (account);
|
||||
boost::network::http::server <rai::rpc>::request request;
|
||||
|
@ -417,7 +417,7 @@ TEST (rpc, wallet_contains)
|
|||
{
|
||||
rai::system system (24000, 1);
|
||||
auto pool (boost::make_shared <boost::network::utils::thread_pool> ());
|
||||
rai::rpc rpc (system.service, pool, 25000, *system.clients [0], true);
|
||||
rai::rpc rpc (system.service, pool, boost::asio::ip::address_v6::loopback (), 25000, *system.clients [0], true);
|
||||
std::string account;
|
||||
rai::test_genesis_key.pub.encode_base58check (account);
|
||||
system.clients [0]->wallet.insert (rai::test_genesis_key.prv);
|
||||
|
@ -443,7 +443,7 @@ TEST (rpc, wallet_doesnt_contain)
|
|||
{
|
||||
rai::system system (24000, 1);
|
||||
auto pool (boost::make_shared <boost::network::utils::thread_pool> ());
|
||||
rai::rpc rpc (system.service, pool, 25000, *system.clients [0], true);
|
||||
rai::rpc rpc (system.service, pool, boost::asio::ip::address_v6::loopback (), 25000, *system.clients [0], true);
|
||||
std::string account;
|
||||
rai::test_genesis_key.pub.encode_base58check (account);
|
||||
boost::network::http::server <rai::rpc>::request request;
|
||||
|
@ -468,7 +468,7 @@ TEST (rpc, validate_account)
|
|||
{
|
||||
rai::system system (24000, 1);
|
||||
auto pool (boost::make_shared <boost::network::utils::thread_pool> ());
|
||||
rai::rpc rpc (system.service, pool, 25000, *system.clients [0], true);
|
||||
rai::rpc rpc (system.service, pool, boost::asio::ip::address_v6::loopback (), 25000, *system.clients [0], true);
|
||||
std::string account;
|
||||
rai::test_genesis_key.pub.encode_base58check (account);
|
||||
system.clients [0]->wallet.insert (rai::test_genesis_key.prv);
|
||||
|
@ -494,7 +494,7 @@ TEST (rpc, validate_account_invalid)
|
|||
{
|
||||
rai::system system (24000, 1);
|
||||
auto pool (boost::make_shared <boost::network::utils::thread_pool> ());
|
||||
rai::rpc rpc (system.service, pool, 25000, *system.clients [0], true);
|
||||
rai::rpc rpc (system.service, pool, boost::asio::ip::address_v6::loopback (), 25000, *system.clients [0], true);
|
||||
std::string account;
|
||||
rai::test_genesis_key.pub.encode_base58check (account);
|
||||
account [0] ^= 0x1;
|
||||
|
@ -521,7 +521,7 @@ TEST (rpc, send)
|
|||
{
|
||||
rai::system system (24000, 1);
|
||||
auto pool (boost::make_shared <boost::network::utils::thread_pool> ());
|
||||
rai::rpc rpc (system.service, pool, 25000, *system.clients [0], true);
|
||||
rai::rpc rpc (system.service, pool, boost::asio::ip::address_v6::loopback (), 25000, *system.clients [0], true);
|
||||
std::string account;
|
||||
rai::test_genesis_key.pub.encode_base58check (account);
|
||||
system.clients [0]->wallet.insert (rai::test_genesis_key.prv);
|
||||
|
@ -550,7 +550,7 @@ TEST (rpc, send_fail)
|
|||
{
|
||||
rai::system system (24000, 1);
|
||||
auto pool (boost::make_shared <boost::network::utils::thread_pool> ());
|
||||
rai::rpc rpc (system.service, pool, 25000, *system.clients [0], true);
|
||||
rai::rpc rpc (system.service, pool, boost::asio::ip::address_v6::loopback (), 25000, *system.clients [0], true);
|
||||
std::string account;
|
||||
rai::test_genesis_key.pub.encode_base58check (account);
|
||||
rai::keypair key1;
|
||||
|
@ -578,7 +578,7 @@ TEST (rpc, wallet_add)
|
|||
{
|
||||
rai::system system (24000, 1);
|
||||
auto pool (boost::make_shared <boost::network::utils::thread_pool> ());
|
||||
rai::rpc rpc (system.service, pool, 25000, *system.clients [0], true);
|
||||
rai::rpc rpc (system.service, pool, boost::asio::ip::address_v6::loopback (), 25000, *system.clients [0], true);
|
||||
rai::keypair key1;
|
||||
std::string key_text;
|
||||
key1.prv.encode_hex (key_text);
|
||||
|
@ -625,7 +625,7 @@ TEST (rpc, wallet_list)
|
|||
{
|
||||
rai::system system (24000, 1);
|
||||
auto pool (boost::make_shared <boost::network::utils::thread_pool> ());
|
||||
rai::rpc rpc (system.service, pool, 25000, *system.clients [0], true);
|
||||
rai::rpc rpc (system.service, pool, boost::asio::ip::address_v6::loopback (), 25000, *system.clients [0], true);
|
||||
std::string account;
|
||||
rai::test_genesis_key.pub.encode_base58check (account);
|
||||
system.clients [0]->wallet.insert (rai::test_genesis_key.prv);
|
||||
|
@ -664,7 +664,7 @@ TEST (rpc, wallet_key_valid)
|
|||
{
|
||||
rai::system system (24000, 1);
|
||||
auto pool (boost::make_shared <boost::network::utils::thread_pool> ());
|
||||
rai::rpc rpc (system.service, pool, 25000, *system.clients [0], true);
|
||||
rai::rpc rpc (system.service, pool, boost::asio::ip::address_v6::loopback (), 25000, *system.clients [0], true);
|
||||
std::string account;
|
||||
rai::test_genesis_key.pub.encode_base58check (account);
|
||||
system.clients [0]->wallet.insert (rai::test_genesis_key.prv);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue