aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/daemon.cpp
diff options
context:
space:
mode:
authorThomas Winget <tewinget@gmail.com>2017-09-05 12:20:27 -0400
committerThomas Winget <tewinget@gmail.com>2017-09-05 12:20:27 -0400
commit77986023c37737e298fc7c3e9938cce0e10d8b80 (patch)
tree81e024d5aea2cdce81f93d155634da6e3c6a2f04 /src/daemon/daemon.cpp
parentRefactor some things into more composable (smaller) functions (diff)
downloadmonero-77986023c37737e298fc7c3e9938cce0e10d8b80.tar.xz
json serialization for rpc-relevant monero types
Structured {de-,}serialization methods for (many new) types which are used for requests or responses in the RPC. New types include RPC requests and responses, and structs which compose types within those. # Conflicts: # src/cryptonote_core/blockchain.cpp
Diffstat (limited to 'src/daemon/daemon.cpp')
-rw-r--r--src/daemon/daemon.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp
index 683eaf4ff..faa620c54 100644
--- a/src/daemon/daemon.cpp
+++ b/src/daemon/daemon.cpp
@@ -32,6 +32,8 @@
#include <stdexcept>
#include "misc_log_ex.h"
#include "daemon/daemon.h"
+#include "rpc/daemon_handler.h"
+#include "rpc/zmq_server.h"
#include "common/password.h"
#include "common/util.h"
@@ -85,7 +87,18 @@ t_daemon::t_daemon(
boost::program_options::variables_map const & vm
)
: mp_internals{new t_internals{vm}}
-{}
+{
+ bool testnet = command_line::get_arg(vm, command_line::arg_testnet_on);
+ if (testnet)
+ {
+ zmq_rpc_bind_port = command_line::get_arg(vm, daemon_args::arg_zmq_testnet_rpc_bind_port);
+ }
+ else
+ {
+ zmq_rpc_bind_port = command_line::get_arg(vm, daemon_args::arg_zmq_rpc_bind_port);
+ }
+ zmq_rpc_bind_address = command_line::get_arg(vm, daemon_args::arg_zmq_rpc_bind_ip);
+}
t_daemon::~t_daemon() = default;
@@ -133,6 +146,30 @@ bool t_daemon::run(bool interactive)
rpc_commands->start_handling(std::bind(&daemonize::t_daemon::stop_p2p, this));
}
+ cryptonote::rpc::DaemonHandler rpc_daemon_handler(mp_internals->core.get(), mp_internals->p2p.get());
+ cryptonote::rpc::ZmqServer zmq_server(rpc_daemon_handler);
+
+ if (!zmq_server.addTCPSocket(zmq_rpc_bind_address, zmq_rpc_bind_port))
+ {
+ LOG_ERROR(std::string("Failed to add TCP Socket (") + zmq_rpc_bind_address
+ + ":" + zmq_rpc_bind_port + ") to ZMQ RPC Server");
+
+ if (interactive)
+ {
+ rpc_commands->stop_handling();
+ }
+
+ mp_internals->rpc.stop();
+
+ return false;
+ }
+
+ MINFO("Starting ZMQ server...");
+ zmq_server.run();
+
+ MINFO(std::string("ZMQ server started at ") + zmq_rpc_bind_address
+ + ":" + zmq_rpc_bind_port + ".");
+
mp_internals->p2p.run(); // blocks until p2p goes down
if (rpc_commands)
@@ -140,6 +177,8 @@ bool t_daemon::run(bool interactive)
rpc_commands->stop_handling();
}
+ zmq_server.stop();
+
mp_internals->rpc.stop();
mp_internals->core.get().get_miner().stop();
MGINFO("Node stopped.");