From 26f7c3d5a9a63026a797e5ff7904498332cb0068 Mon Sep 17 00:00:00 2001 From: Oran Juice Date: Sat, 13 Jun 2015 16:46:13 +0530 Subject: [PATCH] get_block_count, start_save_graph, stop_save_graph IPC --- src/ipc/daemon_ipc_handlers.cpp | 10 ++ src/ipc/include/daemon_ipc_handlers.h | 2 + src/ipc/include/wap_client.h | 10 ++ src/ipc/include/wap_client_engine.inc | 240 +++++++++++++++++++++++--- src/ipc/include/wap_proto.h | 28 ++- src/ipc/include/wap_server_engine.inc | 60 ++++++- src/ipc/wap_client/wap_client.c | 22 +++ src/ipc/wap_proto.c | 102 +++++++++++ src/ipc/wap_server/wap_server.c | 20 +++ src/rpc/daemon_deprecated_rpc.cpp | 69 ++++++++ 10 files changed, 526 insertions(+), 37 deletions(-) diff --git a/src/ipc/daemon_ipc_handlers.cpp b/src/ipc/daemon_ipc_handlers.cpp index caf1b3e83..2e83d7601 100644 --- a/src/ipc/daemon_ipc_handlers.cpp +++ b/src/ipc/daemon_ipc_handlers.cpp @@ -473,5 +473,15 @@ namespace IPC wap_proto_set_status(message, STATUS_OK); } } + + void start_save_graph(wap_proto_t *message) { + p2p->set_save_graph(true); + wap_proto_set_status(message, STATUS_OK); + } + + void stop_save_graph(wap_proto_t *message) { + p2p->set_save_graph(false); + wap_proto_set_status(message, STATUS_OK); + } } } diff --git a/src/ipc/include/daemon_ipc_handlers.h b/src/ipc/include/daemon_ipc_handlers.h index a89159d4a..545712815 100644 --- a/src/ipc/include/daemon_ipc_handlers.h +++ b/src/ipc/include/daemon_ipc_handlers.h @@ -83,6 +83,8 @@ namespace IPC void get_mining_status(wap_proto_t *message); void set_log_hash_rate(wap_proto_t *message); void set_log_level(wap_proto_t *message); + void start_save_graph(wap_proto_t *message); + void stop_save_graph(wap_proto_t *message); void init(cryptonote::core &p_core, nodetool::node_server > &p_p2p, bool p_testnet); diff --git a/src/ipc/include/wap_client.h b/src/ipc/include/wap_client.h index 1e1a58cf7..c39d6b08d 100644 --- a/src/ipc/include/wap_client.h +++ b/src/ipc/include/wap_client.h @@ -137,6 +137,16 @@ WAP_EXPORT int WAP_EXPORT int wap_client_set_log_level (wap_client_t *self, uint8_t level); +// Start save graph +// Returns >= 0 if successful, -1 if interrupted. +WAP_EXPORT int + wap_client_start_save_graph (wap_client_t *self); + +// Stop save graph +// Returns >= 0 if successful, -1 if interrupted. +WAP_EXPORT int + wap_client_stop_save_graph (wap_client_t *self); + // Return last received status WAP_EXPORT int wap_client_status (wap_client_t *self); diff --git a/src/ipc/include/wap_client_engine.inc b/src/ipc/include/wap_client_engine.inc index 14d522b05..3ec540854 100644 --- a/src/ipc/include/wap_client_engine.inc +++ b/src/ipc/include/wap_client_engine.inc @@ -38,10 +38,12 @@ typedef enum { expect_get_mining_status_ok_state = 15, expect_set_log_hash_rate_ok_state = 16, expect_set_log_level_ok_state = 17, - expect_close_ok_state = 18, - defaults_state = 19, - have_error_state = 20, - reexpect_open_ok_state = 21 + expect_start_save_graph_ok_state = 18, + expect_stop_save_graph_ok_state = 19, + expect_close_ok_state = 20, + defaults_state = 21, + have_error_state = 22, + reexpect_open_ok_state = 23 } state_t; typedef enum { @@ -64,27 +66,31 @@ typedef enum { get_mining_status_event = 16, set_log_hash_rate_event = 17, set_log_level_event = 18, - destructor_event = 19, - blocks_ok_event = 20, - get_ok_event = 21, - put_ok_event = 22, - save_bc_ok_event = 23, - start_ok_event = 24, - stop_ok_event = 25, - output_indexes_ok_event = 26, - random_outs_ok_event = 27, - get_height_ok_event = 28, - get_info_ok_event = 29, - get_peer_list_ok_event = 30, - get_mining_status_ok_event = 31, - set_log_hash_rate_ok_event = 32, - set_log_level_ok_event = 33, - close_ok_event = 34, - ping_ok_event = 35, - error_event = 36, - exception_event = 37, - command_invalid_event = 38, - other_event = 39 + start_save_graph_event = 19, + stop_save_graph_event = 20, + destructor_event = 21, + blocks_ok_event = 22, + get_ok_event = 23, + put_ok_event = 24, + save_bc_ok_event = 25, + start_ok_event = 26, + stop_ok_event = 27, + output_indexes_ok_event = 28, + random_outs_ok_event = 29, + get_height_ok_event = 30, + get_info_ok_event = 31, + get_peer_list_ok_event = 32, + get_mining_status_ok_event = 33, + set_log_hash_rate_ok_event = 34, + set_log_level_ok_event = 35, + start_save_graph_ok_event = 36, + stop_save_graph_ok_event = 37, + close_ok_event = 38, + ping_ok_event = 39, + error_event = 40, + exception_event = 41, + command_invalid_event = 42, + other_event = 43 } event_t; // Names for state machine logging and error reporting @@ -108,6 +114,8 @@ s_state_name [] = { "expect get mining status ok", "expect set log hash rate ok", "expect set log level ok", + "expect start save graph ok", + "expect stop save graph ok", "expect close ok", "defaults", "have error", @@ -135,6 +143,8 @@ s_event_name [] = { "GET_MINING_STATUS", "SET_LOG_HASH_RATE", "SET_LOG_LEVEL", + "START_SAVE_GRAPH", + "STOP_SAVE_GRAPH", "destructor", "BLOCKS_OK", "GET_OK", @@ -150,6 +160,8 @@ s_event_name [] = { "GET_MINING_STATUS_OK", "SET_LOG_HASH_RATE_OK", "SET_LOG_LEVEL_OK", + "START_SAVE_GRAPH_OK", + "STOP_SAVE_GRAPH_OK", "CLOSE_OK", "PING_OK", "ERROR", @@ -276,6 +288,10 @@ static void signal_have_set_log_hash_rate_ok (client_t *self); static void signal_have_set_log_level_ok (client_t *self); +static void + signal_have_start_save_graph_ok (client_t *self); +static void + signal_have_stop_save_graph_ok (client_t *self); static void signal_failure (client_t *self); static void @@ -549,6 +565,18 @@ s_protocol_event (s_client_t *self, wap_proto_t *message) case WAP_PROTO_SET_LOG_LEVEL_OK: return set_log_level_ok_event; break; + case WAP_PROTO_START_SAVE_GRAPH: + return start_save_graph_event; + break; + case WAP_PROTO_START_SAVE_GRAPH_OK: + return start_save_graph_ok_event; + break; + case WAP_PROTO_STOP_SAVE_GRAPH: + return stop_save_graph_event; + break; + case WAP_PROTO_STOP_SAVE_GRAPH_OK: + return stop_save_graph_ok_event; + break; case WAP_PROTO_STOP: return stop_event; break; @@ -931,6 +959,30 @@ s_client_execute (s_client_t *self, event_t event) self->state = expect_set_log_level_ok_state; } else + if (self->event == start_save_graph_event) { + if (!self->exception) { + // send START_SAVE_GRAPH + if (wap_client_verbose) + zsys_debug ("wap_client: $ send START_SAVE_GRAPH"); + wap_proto_set_id (self->message, WAP_PROTO_START_SAVE_GRAPH); + wap_proto_send (self->message, self->dealer); + } + if (!self->exception) + self->state = expect_start_save_graph_ok_state; + } + else + if (self->event == stop_save_graph_event) { + if (!self->exception) { + // send STOP_SAVE_GRAPH + if (wap_client_verbose) + zsys_debug ("wap_client: $ send STOP_SAVE_GRAPH"); + wap_proto_set_id (self->message, WAP_PROTO_STOP_SAVE_GRAPH); + wap_proto_send (self->message, self->dealer); + } + if (!self->exception) + self->state = expect_stop_save_graph_ok_state; + } + else if (self->event == destructor_event) { if (!self->exception) { // send CLOSE @@ -1622,6 +1674,96 @@ s_client_execute (s_client_t *self, event_t event) } break; + case expect_start_save_graph_ok_state: + if (self->event == start_save_graph_ok_event) { + if (!self->exception) { + // signal have start save graph ok + if (wap_client_verbose) + zsys_debug ("wap_client: $ signal have start save graph ok"); + signal_have_start_save_graph_ok (&self->client); + } + if (!self->exception) + self->state = connected_state; + } + else + if (self->event == ping_ok_event) { + if (!self->exception) { + // client is connected + if (wap_client_verbose) + zsys_debug ("wap_client: $ client is connected"); + client_is_connected (&self->client); + } + } + else + if (self->event == error_event) { + if (!self->exception) { + // check status code + if (wap_client_verbose) + zsys_debug ("wap_client: $ check status code"); + check_status_code (&self->client); + } + if (!self->exception) + self->state = have_error_state; + } + else + if (self->event == exception_event) { + // No action - just logging + if (wap_client_verbose) + zsys_debug ("wap_client: $ exception"); + } + else { + // Handle unexpected protocol events + // No action - just logging + if (wap_client_verbose) + zsys_debug ("wap_client: $ *"); + } + break; + + case expect_stop_save_graph_ok_state: + if (self->event == stop_save_graph_ok_event) { + if (!self->exception) { + // signal have stop save graph ok + if (wap_client_verbose) + zsys_debug ("wap_client: $ signal have stop save graph ok"); + signal_have_stop_save_graph_ok (&self->client); + } + if (!self->exception) + self->state = connected_state; + } + else + if (self->event == ping_ok_event) { + if (!self->exception) { + // client is connected + if (wap_client_verbose) + zsys_debug ("wap_client: $ client is connected"); + client_is_connected (&self->client); + } + } + else + if (self->event == error_event) { + if (!self->exception) { + // check status code + if (wap_client_verbose) + zsys_debug ("wap_client: $ check status code"); + check_status_code (&self->client); + } + if (!self->exception) + self->state = have_error_state; + } + else + if (self->event == exception_event) { + // No action - just logging + if (wap_client_verbose) + zsys_debug ("wap_client: $ exception"); + } + else { + // Handle unexpected protocol events + // No action - just logging + if (wap_client_verbose) + zsys_debug ("wap_client: $ *"); + } + break; + case expect_close_ok_state: if (self->event == close_ok_event) { if (!self->exception) { @@ -1943,6 +2085,14 @@ s_client_handle_cmdpipe (zloop_t *loop, zsock_t *reader, void *argument) zsock_recv (self->cmdpipe, "1", &self->args.level); s_client_execute (self, set_log_level_event); } + else + if (streq (method, "START SAVE GRAPH")) { + s_client_execute (self, start_save_graph_event); + } + else + if (streq (method, "STOP SAVE GRAPH")) { + s_client_execute (self, stop_save_graph_event); + } // Cleanup pipe if any argument frames are still waiting to be eaten if (zsock_rcvmore (self->cmdpipe)) { zsys_error ("wap_client: trailing API command frames (%s)", method); @@ -2274,6 +2424,14 @@ s_accept_reply (wap_client_t *self, ...) if (streq (reply, "SET LOG LEVEL OK")) { zsock_recv (self->actor, "8", &self->status); } + else + if (streq (reply, "START SAVE GRAPH OK")) { + zsock_recv (self->actor, "8", &self->status); + } + else + if (streq (reply, "STOP SAVE GRAPH OK")) { + zsock_recv (self->actor, "8", &self->status); + } break; } filter = va_arg (args, char *); @@ -2555,6 +2713,38 @@ wap_client_set_log_level (wap_client_t *self, uint8_t level) } +// --------------------------------------------------------------------------- +// Start save graph +// Returns >= 0 if successful, -1 if interrupted. + +int +wap_client_start_save_graph (wap_client_t *self) +{ + assert (self); + + zsock_send (self->actor, "s", "START SAVE GRAPH"); + if (s_accept_reply (self, "START SAVE GRAPH OK", "FAILURE", NULL)) + return -1; // Interrupted or timed-out + return self->status; +} + + +// --------------------------------------------------------------------------- +// Stop save graph +// Returns >= 0 if successful, -1 if interrupted. + +int +wap_client_stop_save_graph (wap_client_t *self) +{ + assert (self); + + zsock_send (self->actor, "s", "STOP SAVE GRAPH"); + if (s_accept_reply (self, "STOP SAVE GRAPH OK", "FAILURE", NULL)) + return -1; // Interrupted or timed-out + return self->status; +} + + // --------------------------------------------------------------------------- // Return last received status diff --git a/src/ipc/include/wap_proto.h b/src/ipc/include/wap_proto.h index 78513f5ad..15b66f468 100644 --- a/src/ipc/include/wap_proto.h +++ b/src/ipc/include/wap_proto.h @@ -132,6 +132,16 @@ ERROR. SET_LOG_LEVEL_OK - This is a codec for a Bitcoin Wallet Access Protocol (RFC tbd) status number 8 Status + START_SAVE_GRAPH - start_save_graph IPC + + START_SAVE_GRAPH_OK - This is a codec for a Bitcoin Wallet Access Protocol (RFC tbd) + status number 8 Status + + STOP_SAVE_GRAPH - stop_save_graph IPC + + STOP_SAVE_GRAPH_OK - This is a codec for a Bitcoin Wallet Access Protocol (RFC tbd) + status number 8 Status + STOP - Wallet asks daemon to start mining. Daemon replies with STOP-OK, or ERROR. @@ -191,13 +201,17 @@ Daemon will reply with CLOSE-OK or ERROR. #define WAP_PROTO_SET_LOG_HASH_RATE_OK 26 #define WAP_PROTO_SET_LOG_LEVEL 27 #define WAP_PROTO_SET_LOG_LEVEL_OK 28 -#define WAP_PROTO_STOP 29 -#define WAP_PROTO_STOP_OK 30 -#define WAP_PROTO_CLOSE 31 -#define WAP_PROTO_CLOSE_OK 32 -#define WAP_PROTO_PING 33 -#define WAP_PROTO_PING_OK 34 -#define WAP_PROTO_ERROR 35 +#define WAP_PROTO_START_SAVE_GRAPH 29 +#define WAP_PROTO_START_SAVE_GRAPH_OK 30 +#define WAP_PROTO_STOP_SAVE_GRAPH 31 +#define WAP_PROTO_STOP_SAVE_GRAPH_OK 32 +#define WAP_PROTO_STOP 33 +#define WAP_PROTO_STOP_OK 34 +#define WAP_PROTO_CLOSE 35 +#define WAP_PROTO_CLOSE_OK 36 +#define WAP_PROTO_PING 37 +#define WAP_PROTO_PING_OK 38 +#define WAP_PROTO_ERROR 39 #include diff --git a/src/ipc/include/wap_server_engine.inc b/src/ipc/include/wap_server_engine.inc index 5e746407f..eaa4f37ce 100644 --- a/src/ipc/include/wap_server_engine.inc +++ b/src/ipc/include/wap_server_engine.inc @@ -45,11 +45,13 @@ typedef enum { get_mining_status_event = 14, set_log_hash_rate_event = 15, set_log_level_event = 16, - close_event = 17, - ping_event = 18, - expired_event = 19, - exception_event = 20, - settled_event = 21 + start_save_graph_event = 17, + stop_save_graph_event = 18, + close_event = 19, + ping_event = 20, + expired_event = 21, + exception_event = 22, + settled_event = 23 } event_t; // Names for state machine logging and error reporting @@ -81,6 +83,8 @@ s_event_name [] = { "GET_MINING_STATUS", "SET_LOG_HASH_RATE", "SET_LOG_LEVEL", + "START_SAVE_GRAPH", + "STOP_SAVE_GRAPH", "CLOSE", "PING", "expired", @@ -178,6 +182,10 @@ static void set_log_hash_rate (client_t *self); static void set_log_level (client_t *self); +static void + start_save_graph (client_t *self); +static void + stop_save_graph (client_t *self); static void deregister_wallet (client_t *self); static void @@ -404,6 +412,12 @@ s_protocol_event (wap_proto_t *message) case WAP_PROTO_SET_LOG_LEVEL: return set_log_level_event; break; + case WAP_PROTO_START_SAVE_GRAPH: + return start_save_graph_event; + break; + case WAP_PROTO_STOP_SAVE_GRAPH: + return stop_save_graph_event; + break; case WAP_PROTO_STOP: return stop_event; break; @@ -874,6 +888,42 @@ s_client_execute (s_client_t *self, event_t event) } } else + if (self->event == start_save_graph_event) { + if (!self->exception) { + // start save graph + if (self->server->verbose) + zsys_debug ("%s: $ start save graph", self->log_prefix); + start_save_graph (&self->client); + } + if (!self->exception) { + // send START_SAVE_GRAPH_OK + if (self->server->verbose) + zsys_debug ("%s: $ send START_SAVE_GRAPH_OK", + self->log_prefix); + wap_proto_set_id (self->server->message, WAP_PROTO_START_SAVE_GRAPH_OK); + wap_proto_set_routing_id (self->server->message, self->routing_id); + wap_proto_send (self->server->message, self->server->router); + } + } + else + if (self->event == stop_save_graph_event) { + if (!self->exception) { + // stop save graph + if (self->server->verbose) + zsys_debug ("%s: $ stop save graph", self->log_prefix); + stop_save_graph (&self->client); + } + if (!self->exception) { + // send STOP_SAVE_GRAPH_OK + if (self->server->verbose) + zsys_debug ("%s: $ send STOP_SAVE_GRAPH_OK", + self->log_prefix); + wap_proto_set_id (self->server->message, WAP_PROTO_STOP_SAVE_GRAPH_OK); + wap_proto_set_routing_id (self->server->message, self->routing_id); + wap_proto_send (self->server->message, self->server->router); + } + } + else if (self->event == close_event) { if (!self->exception) { // send CLOSE_OK diff --git a/src/ipc/wap_client/wap_client.c b/src/ipc/wap_client/wap_client.c index e985b54eb..8973abe6e 100644 --- a/src/ipc/wap_client/wap_client.c +++ b/src/ipc/wap_client/wap_client.c @@ -466,3 +466,25 @@ signal_have_set_log_level_ok (client_t *self) zsock_send (self->cmdpipe, "s8", "SET LOG LEVEL OK", wap_proto_status (self->message)); } + +// --------------------------------------------------------------------------- +// signal_have_start_save_graph_ok +// + +static void +signal_have_start_save_graph_ok (client_t *self) +{ + zsock_send (self->cmdpipe, "s8", "START SAVE GRAPH OK", + wap_proto_status (self->message)); +} + +// --------------------------------------------------------------------------- +// signal_have_stop_save_graph_ok +// + +static void +signal_have_stop_save_graph_ok (client_t *self) +{ + zsock_send (self->cmdpipe, "s8", "STOP SAVE GRAPH OK", + wap_proto_status (self->message)); +} diff --git a/src/ipc/wap_proto.c b/src/ipc/wap_proto.c index 849da4f81..6a6f0af26 100644 --- a/src/ipc/wap_proto.c +++ b/src/ipc/wap_proto.c @@ -554,6 +554,20 @@ wap_proto_recv (wap_proto_t *self, zsock_t *input) GET_NUMBER8 (self->status); break; + case WAP_PROTO_START_SAVE_GRAPH: + break; + + case WAP_PROTO_START_SAVE_GRAPH_OK: + GET_NUMBER8 (self->status); + break; + + case WAP_PROTO_STOP_SAVE_GRAPH: + break; + + case WAP_PROTO_STOP_SAVE_GRAPH_OK: + GET_NUMBER8 (self->status); + break; + case WAP_PROTO_STOP: break; @@ -714,6 +728,12 @@ wap_proto_send (wap_proto_t *self, zsock_t *output) case WAP_PROTO_SET_LOG_LEVEL_OK: frame_size += 8; // status break; + case WAP_PROTO_START_SAVE_GRAPH_OK: + frame_size += 8; // status + break; + case WAP_PROTO_STOP_SAVE_GRAPH_OK: + frame_size += 8; // status + break; case WAP_PROTO_ERROR: frame_size += 2; // status frame_size += 1 + strlen (self->reason); @@ -902,6 +922,14 @@ wap_proto_send (wap_proto_t *self, zsock_t *output) PUT_NUMBER8 (self->status); break; + case WAP_PROTO_START_SAVE_GRAPH_OK: + PUT_NUMBER8 (self->status); + break; + + case WAP_PROTO_STOP_SAVE_GRAPH_OK: + PUT_NUMBER8 (self->status); + break; + case WAP_PROTO_ERROR: PUT_NUMBER2 (self->status); PUT_STRING (self->reason); @@ -1164,6 +1192,24 @@ wap_proto_print (wap_proto_t *self) zsys_debug (" status=%ld", (long) self->status); break; + case WAP_PROTO_START_SAVE_GRAPH: + zsys_debug ("WAP_PROTO_START_SAVE_GRAPH:"); + break; + + case WAP_PROTO_START_SAVE_GRAPH_OK: + zsys_debug ("WAP_PROTO_START_SAVE_GRAPH_OK:"); + zsys_debug (" status=%ld", (long) self->status); + break; + + case WAP_PROTO_STOP_SAVE_GRAPH: + zsys_debug ("WAP_PROTO_STOP_SAVE_GRAPH:"); + break; + + case WAP_PROTO_STOP_SAVE_GRAPH_OK: + zsys_debug ("WAP_PROTO_STOP_SAVE_GRAPH_OK:"); + zsys_debug (" status=%ld", (long) self->status); + break; + case WAP_PROTO_STOP: zsys_debug ("WAP_PROTO_STOP:"); break; @@ -1325,6 +1371,18 @@ wap_proto_command (wap_proto_t *self) case WAP_PROTO_SET_LOG_LEVEL_OK: return ("SET_LOG_LEVEL_OK"); break; + case WAP_PROTO_START_SAVE_GRAPH: + return ("START_SAVE_GRAPH"); + break; + case WAP_PROTO_START_SAVE_GRAPH_OK: + return ("START_SAVE_GRAPH_OK"); + break; + case WAP_PROTO_STOP_SAVE_GRAPH: + return ("STOP_SAVE_GRAPH"); + break; + case WAP_PROTO_STOP_SAVE_GRAPH_OK: + return ("STOP_SAVE_GRAPH_OK"); + break; case WAP_PROTO_STOP: return ("STOP"); break; @@ -2539,6 +2597,50 @@ wap_proto_test (bool verbose) wap_proto_send (self, output); wap_proto_send (self, output); + for (instance = 0; instance < 2; instance++) { + wap_proto_recv (self, input); + assert (wap_proto_routing_id (self)); + assert (wap_proto_status (self) == 123); + } + wap_proto_set_id (self, WAP_PROTO_START_SAVE_GRAPH); + + // Send twice + wap_proto_send (self, output); + wap_proto_send (self, output); + + for (instance = 0; instance < 2; instance++) { + wap_proto_recv (self, input); + assert (wap_proto_routing_id (self)); + } + wap_proto_set_id (self, WAP_PROTO_START_SAVE_GRAPH_OK); + + wap_proto_set_status (self, 123); + // Send twice + wap_proto_send (self, output); + wap_proto_send (self, output); + + for (instance = 0; instance < 2; instance++) { + wap_proto_recv (self, input); + assert (wap_proto_routing_id (self)); + assert (wap_proto_status (self) == 123); + } + wap_proto_set_id (self, WAP_PROTO_STOP_SAVE_GRAPH); + + // Send twice + wap_proto_send (self, output); + wap_proto_send (self, output); + + for (instance = 0; instance < 2; instance++) { + wap_proto_recv (self, input); + assert (wap_proto_routing_id (self)); + } + wap_proto_set_id (self, WAP_PROTO_STOP_SAVE_GRAPH_OK); + + wap_proto_set_status (self, 123); + // Send twice + wap_proto_send (self, output); + wap_proto_send (self, output); + for (instance = 0; instance < 2; instance++) { wap_proto_recv (self, input); assert (wap_proto_routing_id (self)); diff --git a/src/ipc/wap_server/wap_server.c b/src/ipc/wap_server/wap_server.c index 8e0eef5cf..699a9c11a 100644 --- a/src/ipc/wap_server/wap_server.c +++ b/src/ipc/wap_server/wap_server.c @@ -342,3 +342,23 @@ set_log_level (client_t *self) { IPC::Daemon::set_log_level(self->message); } + +// --------------------------------------------------------------------------- +// start_save_graph +// + +static void +start_save_graph (client_t *self) +{ + IPC::Daemon::start_save_graph(self->message); +} + +// --------------------------------------------------------------------------- +// stop_save_graph +// + +static void +stop_save_graph (client_t *self) +{ + IPC::Daemon::stop_save_graph(self->message); +} diff --git a/src/rpc/daemon_deprecated_rpc.cpp b/src/rpc/daemon_deprecated_rpc.cpp index 8b3ed389d..338ef2015 100644 --- a/src/rpc/daemon_deprecated_rpc.cpp +++ b/src/rpc/daemon_deprecated_rpc.cpp @@ -432,6 +432,69 @@ namespace return ns_rpc_create_reply(buf, len, req, "{s:s}", "status", STATUS_OK); } + /*! + * \brief Implementation of 'getblockcount' method. + * \param buf Buffer to fill in response. + * \param len Max length of response. + * \param req net_skeleton RPC request + * \return Actual response length. + */ + int getblockcount(char *buf, int len, struct ns_rpc_request *req) + { + connect_to_daemon(); + int rc = wap_client_get_height(ipc_client); + if (rc < 0) { + return ns_rpc_create_error(buf, len, req, daemon_connection_error, + "Couldn't connect to daemon.", "{}"); + } + uint64_t count = wap_client_height(ipc_client); + rapidjson::Document response_json; + rapidjson::Value result_json; + result_json.SetObject(); + result_json.AddMember("count", count, response_json.GetAllocator()); + result_json.AddMember("status", "OK", response_json.GetAllocator()); + std::string response; + construct_response_string(req, result_json, response_json, response); + size_t copy_length = ((uint32_t)len > response.length()) ? response.length() + 1 : (uint32_t)len; + strncpy(buf, response.c_str(), copy_length); + return response.length(); + } + + /*! + * \brief Implementation of 'startsavegraph' method. + * \param buf Buffer to fill in response. + * \param len Max length of response. + * \param req net_skeleton RPC request + * \return Actual response length. + */ + int startsavegraph(char *buf, int len, struct ns_rpc_request *req) + { + connect_to_daemon(); + int rc = wap_client_start_save_graph(ipc_client); + if (rc < 0) { + return ns_rpc_create_error(buf, len, req, daemon_connection_error, + "Couldn't connect to daemon.", "{}"); + } + return ns_rpc_create_reply(buf, len, req, "{s:s}", "status", STATUS_OK); + } + + /*! + * \brief Implementation of 'stopsavegraph' method. + * \param buf Buffer to fill in response. + * \param len Max length of response. + * \param req net_skeleton RPC request + * \return Actual response length. + */ + int stopsavegraph(char *buf, int len, struct ns_rpc_request *req) + { + connect_to_daemon(); + int rc = wap_client_stop_save_graph(ipc_client); + if (rc < 0) { + return ns_rpc_create_error(buf, len, req, daemon_connection_error, + "Couldn't connect to daemon.", "{}"); + } + return ns_rpc_create_reply(buf, len, req, "{s:s}", "status", STATUS_OK); + } // Contains a list of method names. const char *method_names[] = { "getheight", @@ -442,6 +505,9 @@ namespace "getminingstatus", "setloghashrate", "setloglevel", + "getblockcount", + "startsavegraph", + "stopsavegraph", NULL }; @@ -455,6 +521,9 @@ namespace getminingstatus, setloghashrate, setloglevel, + getblockcount, + startsavegraph, + stopsavegraph, NULL };