Skip to content

Commit

Permalink
Use shared_ptr for storing rpc component
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 27, 2024
1 parent 2fd368a commit f741d58
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion nano/nano_node/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag

nano::ipc::ipc_server ipc_server (*node, config.rpc);
std::unique_ptr<boost::process::child> rpc_process;
std::unique_ptr<nano::rpc> rpc;
std::shared_ptr<nano::rpc> rpc;
std::unique_ptr<nano::rpc_handler_interface> rpc_handler;
if (config.rpc_enable)
{
Expand Down
10 changes: 3 additions & 7 deletions nano/rpc/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,16 @@ void nano::rpc::stop ()
acceptor.close ();
}

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::shared_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;

if (config_a.tls_config && config_a.tls_config->enable_https)
{
#ifdef NANO_SECURE_RPC
impl = std::make_unique<rpc_secure> (io_ctx_a, config_a, rpc_handler_interface_a);
return std::make_shared<nano::rpc_secure> (io_ctx_a, config_a, rpc_handler_interface_a);
#endif
}
else
{
impl = std::make_unique<rpc> (io_ctx_a, config_a, rpc_handler_interface_a);
return std::make_shared<nano::rpc> (io_ctx_a, config_a, rpc_handler_interface_a);
}

return impl;
}
2 changes: 1 addition & 1 deletion nano/rpc/rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ class rpc : public std::enable_shared_from_this<rpc>
};

/** Returns the correct RPC implementation based on TLS configuration */
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);
std::shared_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);
}

0 comments on commit f741d58

Please sign in to comment.