Skip to content

Commit

Permalink
RPC SHARED IO_CTX
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 19, 2024
1 parent 3f49cc1 commit 1bf562b
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion nano/nano_node/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag
}
});
});
rpc = nano::get_rpc (*io_ctx, rpc_config, *rpc_handler);
rpc = nano::get_rpc (io_ctx, rpc_config, *rpc_handler);
rpc->start ();
}
else
Expand Down
2 changes: 1 addition & 1 deletion nano/nano_rpc/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void run (std::filesystem::path const & data_path, std::vector<std::string> cons
try
{
nano::ipc_rpc_processor ipc_rpc_processor (*io_ctx, rpc_config);
auto rpc = nano::get_rpc (*io_ctx, rpc_config, ipc_rpc_processor);
auto rpc = nano::get_rpc (io_ctx, rpc_config, ipc_rpc_processor);
rpc->start ();

debug_assert (!nano::signal_handler_impl);
Expand Down
2 changes: 1 addition & 1 deletion nano/nano_wallet/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ int run_wallet (QApplication & application, int argc, char * const * argv, std::
}
rpc_config.tls_config = tls_config;
rpc_handler = std::make_unique<nano::inprocess_rpc_handler> (*node, ipc, config.rpc);
rpc = nano::get_rpc (*io_ctx, rpc_config, *rpc_handler);
rpc = nano::get_rpc (io_ctx, rpc_config, *rpc_handler);
rpc->start ();
}
else
Expand Down
9 changes: 5 additions & 4 deletions nano/rpc/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
#include <nano/rpc/rpc_secure.hpp>
#endif

nano::rpc::rpc (boost::asio::io_context & io_ctx_a, nano::rpc_config config_a, nano::rpc_handler_interface & rpc_handler_interface_a) :
nano::rpc::rpc (std::shared_ptr<boost::asio::io_context> io_ctx_a, nano::rpc_config config_a, nano::rpc_handler_interface & rpc_handler_interface_a) :
config (std::move (config_a)),
acceptor (io_ctx_a),
io_ctx (io_ctx_a),
io_ctx_shared (io_ctx_a),
io_ctx (*io_ctx_shared),
acceptor (io_ctx),
rpc_handler_interface (rpc_handler_interface_a)
{
rpc_handler_interface.rpc_instance (*this);
Expand Down Expand Up @@ -78,7 +79,7 @@ void nano::rpc::stop ()
acceptor.close ();
}

std::unique_ptr<nano::rpc> nano::get_rpc (boost::asio::io_context & io_ctx_a, nano::rpc_config const & config_a, nano::rpc_handler_interface & rpc_handler_interface_a)
std::unique_ptr<nano::rpc> nano::get_rpc (std::shared_ptr<boost::asio::io_context> io_ctx_a, nano::rpc_config const & config_a, nano::rpc_handler_interface & rpc_handler_interface_a)
{
std::unique_ptr<rpc> impl;

Expand Down
14 changes: 9 additions & 5 deletions nano/rpc/rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,29 @@ class rpc_handler_interface;
class rpc
{
public:
rpc (boost::asio::io_context & io_ctx_a, nano::rpc_config config_a, nano::rpc_handler_interface & rpc_handler_interface_a);
rpc (std::shared_ptr<boost::asio::io_context>, nano::rpc_config config_a, nano::rpc_handler_interface & rpc_handler_interface_a);
virtual ~rpc ();

void start ();
virtual void accept ();
void stop ();

std::uint16_t listening_port ()
virtual void accept ();

std::uint16_t listening_port () const
{
return acceptor.local_endpoint ().port ();
}

public:
nano::logger logger{ "rpc" };
nano::rpc_config config;
boost::asio::ip::tcp::acceptor acceptor;
std::shared_ptr<boost::asio::io_context> io_ctx_shared;
boost::asio::io_context & io_ctx;
boost::asio::ip::tcp::acceptor acceptor;
nano::rpc_handler_interface & rpc_handler_interface;
bool stopped{ false };
};

/** Returns the correct RPC implementation based on TLS configuration */
std::unique_ptr<nano::rpc> get_rpc (boost::asio::io_context & io_ctx_a, nano::rpc_config const & config_a, nano::rpc_handler_interface & rpc_handler_interface_a);
std::unique_ptr<nano::rpc> get_rpc (std::shared_ptr<boost::asio::io_context>, nano::rpc_config const & config_a, nano::rpc_handler_interface & rpc_handler_interface_a);
}
2 changes: 1 addition & 1 deletion nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6047,7 +6047,7 @@ TEST (rpc, simultaneous_calls)
ASSERT_TRUE (ipc_tcp_port.has_value ());
rpc_config.rpc_process.num_ipc_connections = 8;
nano::ipc_rpc_processor ipc_rpc_processor (*system.io_ctx, rpc_config, ipc_tcp_port.value ());
nano::rpc rpc (*system.io_ctx, rpc_config, ipc_rpc_processor);
nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor);
rpc.start ();
boost::property_tree::ptree request;
request.put ("action", "account_block_count");
Expand Down
2 changes: 1 addition & 1 deletion nano/rpc_test/rpc_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ nano::test::rpc_context nano::test::add_rpc (nano::test::system & system, std::s
const auto ipc_tcp_port = ipc_server->listening_tcp_port ();
debug_assert (ipc_tcp_port.has_value ());
auto ipc_rpc_processor (std::make_unique<nano::ipc_rpc_processor> (*system.io_ctx, rpc_config, ipc_tcp_port.value ()));
auto rpc (std::make_shared<nano::rpc> (*system.io_ctx, rpc_config, *ipc_rpc_processor));
auto rpc (std::make_shared<nano::rpc> (system.io_ctx, rpc_config, *ipc_rpc_processor));
rpc->start ();

return rpc_context{ rpc, ipc_server, ipc_rpc_processor, node_rpc_config };
Expand Down
2 changes: 1 addition & 1 deletion nano/slow_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class rpc_wrapper
rpc_config{ node.network_params.network, port, true },
ipc{ node, node_rpc_config },
ipc_rpc_processor{ *system.io_ctx, rpc_config },
rpc{ *system.io_ctx, rpc_config, ipc_rpc_processor }
rpc{ system.io_ctx, rpc_config, ipc_rpc_processor }
{
}

Expand Down

0 comments on commit 1bf562b

Please sign in to comment.