set_log_hash_rate, set_log_level IPC and deprecated RPC
This commit is contained in:
parent
919c067d72
commit
65c98639e7
|
@ -444,5 +444,34 @@ namespace IPC
|
|||
|
||||
wap_proto_set_status(message, STATUS_OK);
|
||||
}
|
||||
|
||||
void set_log_hash_rate(wap_proto_t *message) {
|
||||
if (core->get_miner().is_mining())
|
||||
{
|
||||
core->get_miner().do_print_hashrate(wap_proto_visible(message));
|
||||
wap_proto_set_status(message, STATUS_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
wap_proto_set_status(message, STATUS_NOT_MINING);
|
||||
}
|
||||
}
|
||||
|
||||
void set_log_level(wap_proto_t *message) {
|
||||
// zproto supports only unsigned integers afaik. so the log level is sent as
|
||||
// one and casted to signed int here.
|
||||
int8_t level = (int8_t)wap_proto_level(message);
|
||||
if (level < LOG_LEVEL_MIN || level > LOG_LEVEL_MAX)
|
||||
{
|
||||
wap_proto_set_status(message, STATUS_INVALID_LOG_LEVEL);
|
||||
}
|
||||
else
|
||||
{
|
||||
epee::log_space::log_singletone::get_set_log_detalisation_level(true, level);
|
||||
int otshell_utils_log_level = 100 - (level * 20);
|
||||
gCurrentLogger.setDebugLevel(otshell_utils_log_level);
|
||||
wap_proto_set_status(message, STATUS_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,8 @@ namespace IPC
|
|||
const uint64_t STATUS_TX_NOT_RELAYED = 8;
|
||||
const uint64_t STATUS_RANDOM_OUTS_FAILED = 9;
|
||||
const uint64_t STATUS_MINING_NOT_STOPPED = 10;
|
||||
const uint64_t STATUS_NOT_MINING = 11;
|
||||
const uint64_t STATUS_INVALID_LOG_LEVEL = 11;
|
||||
const uint64_t STATUS_ERROR_STORING_BLOCKCHAIN = 11;
|
||||
namespace Daemon
|
||||
{
|
||||
|
@ -79,6 +81,8 @@ namespace IPC
|
|||
void get_info(wap_proto_t *message);
|
||||
void get_peer_list(wap_proto_t *message);
|
||||
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 init(cryptonote::core &p_core,
|
||||
nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> > &p_p2p,
|
||||
bool p_testnet);
|
||||
|
|
|
@ -127,6 +127,16 @@ WAP_EXPORT int
|
|||
WAP_EXPORT int
|
||||
wap_client_get_mining_status (wap_client_t *self);
|
||||
|
||||
// Set log hash rate
|
||||
// Returns >= 0 if successful, -1 if interrupted.
|
||||
WAP_EXPORT int
|
||||
wap_client_set_log_hash_rate (wap_client_t *self, uint8_t visible);
|
||||
|
||||
// Set log hash rate
|
||||
// Returns >= 0 if successful, -1 if interrupted.
|
||||
WAP_EXPORT int
|
||||
wap_client_set_log_level (wap_client_t *self, uint8_t level);
|
||||
|
||||
// Return last received status
|
||||
WAP_EXPORT int
|
||||
wap_client_status (wap_client_t *self);
|
||||
|
|
|
@ -36,10 +36,12 @@ typedef enum {
|
|||
expect_get_info_ok_state = 13,
|
||||
expect_get_peer_list_ok_state = 14,
|
||||
expect_get_mining_status_ok_state = 15,
|
||||
expect_close_ok_state = 16,
|
||||
defaults_state = 17,
|
||||
have_error_state = 18,
|
||||
reexpect_open_ok_state = 19
|
||||
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
|
||||
} state_t;
|
||||
|
||||
typedef enum {
|
||||
|
@ -60,25 +62,29 @@ typedef enum {
|
|||
get_info_event = 14,
|
||||
get_peer_list_event = 15,
|
||||
get_mining_status_event = 16,
|
||||
destructor_event = 17,
|
||||
blocks_ok_event = 18,
|
||||
get_ok_event = 19,
|
||||
put_ok_event = 20,
|
||||
save_bc_ok_event = 21,
|
||||
start_ok_event = 22,
|
||||
stop_ok_event = 23,
|
||||
output_indexes_ok_event = 24,
|
||||
random_outs_ok_event = 25,
|
||||
get_height_ok_event = 26,
|
||||
get_info_ok_event = 27,
|
||||
get_peer_list_ok_event = 28,
|
||||
get_mining_status_ok_event = 29,
|
||||
close_ok_event = 30,
|
||||
ping_ok_event = 31,
|
||||
error_event = 32,
|
||||
exception_event = 33,
|
||||
command_invalid_event = 34,
|
||||
other_event = 35
|
||||
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
|
||||
} event_t;
|
||||
|
||||
// Names for state machine logging and error reporting
|
||||
|
@ -100,6 +106,8 @@ s_state_name [] = {
|
|||
"expect get info ok",
|
||||
"expect get peer list ok",
|
||||
"expect get mining status ok",
|
||||
"expect set log hash rate ok",
|
||||
"expect set log level ok",
|
||||
"expect close ok",
|
||||
"defaults",
|
||||
"have error",
|
||||
|
@ -125,6 +133,8 @@ s_event_name [] = {
|
|||
"GET_INFO",
|
||||
"GET_PEER_LIST",
|
||||
"GET_MINING_STATUS",
|
||||
"SET_LOG_HASH_RATE",
|
||||
"SET_LOG_LEVEL",
|
||||
"destructor",
|
||||
"BLOCKS_OK",
|
||||
"GET_OK",
|
||||
|
@ -138,6 +148,8 @@ s_event_name [] = {
|
|||
"GET_INFO_OK",
|
||||
"GET_PEER_LIST_OK",
|
||||
"GET_MINING_STATUS_OK",
|
||||
"SET_LOG_HASH_RATE_OK",
|
||||
"SET_LOG_LEVEL_OK",
|
||||
"CLOSE_OK",
|
||||
"PING_OK",
|
||||
"ERROR",
|
||||
|
@ -165,6 +177,8 @@ struct _client_args_t {
|
|||
zframe_t *amounts;
|
||||
zchunk_t *address;
|
||||
uint64_t thread_count;
|
||||
uint8_t visible;
|
||||
uint8_t level;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
@ -228,6 +242,10 @@ static void
|
|||
prepare_get_output_indexes_command (client_t *self);
|
||||
static void
|
||||
prepare_get_random_outs_command (client_t *self);
|
||||
static void
|
||||
prepare_set_log_hash_rate_command (client_t *self);
|
||||
static void
|
||||
prepare_set_log_level_command (client_t *self);
|
||||
static void
|
||||
check_if_connection_is_dead (client_t *self);
|
||||
static void
|
||||
|
@ -254,6 +272,10 @@ static void
|
|||
signal_have_get_peer_list_ok (client_t *self);
|
||||
static void
|
||||
signal_have_get_mining_status_ok (client_t *self);
|
||||
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_failure (client_t *self);
|
||||
static void
|
||||
|
@ -515,6 +537,18 @@ s_protocol_event (s_client_t *self, wap_proto_t *message)
|
|||
case WAP_PROTO_GET_MINING_STATUS_OK:
|
||||
return get_mining_status_ok_event;
|
||||
break;
|
||||
case WAP_PROTO_SET_LOG_HASH_RATE:
|
||||
return set_log_hash_rate_event;
|
||||
break;
|
||||
case WAP_PROTO_SET_LOG_HASH_RATE_OK:
|
||||
return set_log_hash_rate_ok_event;
|
||||
break;
|
||||
case WAP_PROTO_SET_LOG_LEVEL:
|
||||
return set_log_level_event;
|
||||
break;
|
||||
case WAP_PROTO_SET_LOG_LEVEL_OK:
|
||||
return set_log_level_ok_event;
|
||||
break;
|
||||
case WAP_PROTO_STOP:
|
||||
return stop_event;
|
||||
break;
|
||||
|
@ -861,6 +895,42 @@ s_client_execute (s_client_t *self, event_t event)
|
|||
self->state = expect_get_mining_status_ok_state;
|
||||
}
|
||||
else
|
||||
if (self->event == set_log_hash_rate_event) {
|
||||
if (!self->exception) {
|
||||
// prepare set log hash rate command
|
||||
if (wap_client_verbose)
|
||||
zsys_debug ("wap_client: $ prepare set log hash rate command");
|
||||
prepare_set_log_hash_rate_command (&self->client);
|
||||
}
|
||||
if (!self->exception) {
|
||||
// send SET_LOG_HASH_RATE
|
||||
if (wap_client_verbose)
|
||||
zsys_debug ("wap_client: $ send SET_LOG_HASH_RATE");
|
||||
wap_proto_set_id (self->message, WAP_PROTO_SET_LOG_HASH_RATE);
|
||||
wap_proto_send (self->message, self->dealer);
|
||||
}
|
||||
if (!self->exception)
|
||||
self->state = expect_set_log_hash_rate_ok_state;
|
||||
}
|
||||
else
|
||||
if (self->event == set_log_level_event) {
|
||||
if (!self->exception) {
|
||||
// prepare set log level command
|
||||
if (wap_client_verbose)
|
||||
zsys_debug ("wap_client: $ prepare set log level command");
|
||||
prepare_set_log_level_command (&self->client);
|
||||
}
|
||||
if (!self->exception) {
|
||||
// send SET_LOG_LEVEL
|
||||
if (wap_client_verbose)
|
||||
zsys_debug ("wap_client: $ send SET_LOG_LEVEL");
|
||||
wap_proto_set_id (self->message, WAP_PROTO_SET_LOG_LEVEL);
|
||||
wap_proto_send (self->message, self->dealer);
|
||||
}
|
||||
if (!self->exception)
|
||||
self->state = expect_set_log_level_ok_state;
|
||||
}
|
||||
else
|
||||
if (self->event == destructor_event) {
|
||||
if (!self->exception) {
|
||||
// send CLOSE
|
||||
|
@ -1462,6 +1532,96 @@ s_client_execute (s_client_t *self, event_t event)
|
|||
}
|
||||
break;
|
||||
|
||||
case expect_set_log_hash_rate_ok_state:
|
||||
if (self->event == set_log_hash_rate_ok_event) {
|
||||
if (!self->exception) {
|
||||
// signal have set log hash rate ok
|
||||
if (wap_client_verbose)
|
||||
zsys_debug ("wap_client: $ signal have set log hash rate ok");
|
||||
signal_have_set_log_hash_rate_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_set_log_level_ok_state:
|
||||
if (self->event == set_log_level_ok_event) {
|
||||
if (!self->exception) {
|
||||
// signal have set log level ok
|
||||
if (wap_client_verbose)
|
||||
zsys_debug ("wap_client: $ signal have set log level ok");
|
||||
signal_have_set_log_level_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) {
|
||||
|
@ -1773,6 +1933,16 @@ s_client_handle_cmdpipe (zloop_t *loop, zsock_t *reader, void *argument)
|
|||
if (streq (method, "GET MINING STATUS")) {
|
||||
s_client_execute (self, get_mining_status_event);
|
||||
}
|
||||
else
|
||||
if (streq (method, "SET LOG HASH RATE")) {
|
||||
zsock_recv (self->cmdpipe, "1", &self->args.visible);
|
||||
s_client_execute (self, set_log_hash_rate_event);
|
||||
}
|
||||
else
|
||||
if (streq (method, "SET LOG LEVEL")) {
|
||||
zsock_recv (self->cmdpipe, "1", &self->args.level);
|
||||
s_client_execute (self, set_log_level_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);
|
||||
|
@ -2096,6 +2266,14 @@ s_accept_reply (wap_client_t *self, ...)
|
|||
zchunk_destroy (&self->address);
|
||||
zsock_recv (self->actor, "8188p", &self->status, &self->active, &self->speed, &self->thread_count, &self->address);
|
||||
}
|
||||
else
|
||||
if (streq (reply, "SET LOG HASH RATE OK")) {
|
||||
zsock_recv (self->actor, "8", &self->status);
|
||||
}
|
||||
else
|
||||
if (streq (reply, "SET LOG LEVEL OK")) {
|
||||
zsock_recv (self->actor, "8", &self->status);
|
||||
}
|
||||
break;
|
||||
}
|
||||
filter = va_arg (args, char *);
|
||||
|
@ -2345,6 +2523,38 @@ wap_client_get_mining_status (wap_client_t *self)
|
|||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Set log hash rate
|
||||
// Returns >= 0 if successful, -1 if interrupted.
|
||||
|
||||
int
|
||||
wap_client_set_log_hash_rate (wap_client_t *self, uint8_t visible)
|
||||
{
|
||||
assert (self);
|
||||
|
||||
zsock_send (self->actor, "s1", "SET LOG HASH RATE", visible);
|
||||
if (s_accept_reply (self, "SET LOG HASH RATE OK", "FAILURE", NULL))
|
||||
return -1; // Interrupted or timed-out
|
||||
return self->status;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Set log hash rate
|
||||
// Returns >= 0 if successful, -1 if interrupted.
|
||||
|
||||
int
|
||||
wap_client_set_log_level (wap_client_t *self, uint8_t level)
|
||||
{
|
||||
assert (self);
|
||||
|
||||
zsock_send (self->actor, "s1", "SET LOG LEVEL", level);
|
||||
if (s_accept_reply (self, "SET LOG LEVEL OK", "FAILURE", NULL))
|
||||
return -1; // Interrupted or timed-out
|
||||
return self->status;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Return last received status
|
||||
|
||||
|
|
|
@ -120,6 +120,18 @@ ERROR.
|
|||
thread_count number 8 Threads count
|
||||
address chunk Address
|
||||
|
||||
SET_LOG_HASH_RATE - set_log_hash_rate IPC
|
||||
visible number 1 Visible
|
||||
|
||||
SET_LOG_HASH_RATE_OK - This is a codec for a Bitcoin Wallet Access Protocol (RFC tbd)
|
||||
status number 8 Status
|
||||
|
||||
SET_LOG_LEVEL - set_log_level IPC
|
||||
level number 1 Level
|
||||
|
||||
SET_LOG_LEVEL_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.
|
||||
|
||||
|
@ -175,13 +187,17 @@ Daemon will reply with CLOSE-OK or ERROR.
|
|||
#define WAP_PROTO_GET_PEER_LIST_OK 22
|
||||
#define WAP_PROTO_GET_MINING_STATUS 23
|
||||
#define WAP_PROTO_GET_MINING_STATUS_OK 24
|
||||
#define WAP_PROTO_STOP 25
|
||||
#define WAP_PROTO_STOP_OK 26
|
||||
#define WAP_PROTO_CLOSE 27
|
||||
#define WAP_PROTO_CLOSE_OK 28
|
||||
#define WAP_PROTO_PING 29
|
||||
#define WAP_PROTO_PING_OK 30
|
||||
#define WAP_PROTO_ERROR 31
|
||||
#define WAP_PROTO_SET_LOG_HASH_RATE 25
|
||||
#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
|
||||
|
||||
#include <czmq.h>
|
||||
|
||||
|
@ -449,6 +465,18 @@ uint64_t
|
|||
void
|
||||
wap_proto_set_speed (wap_proto_t *self, uint64_t speed);
|
||||
|
||||
// Get/set the visible field
|
||||
byte
|
||||
wap_proto_visible (wap_proto_t *self);
|
||||
void
|
||||
wap_proto_set_visible (wap_proto_t *self, byte visible);
|
||||
|
||||
// Get/set the level field
|
||||
byte
|
||||
wap_proto_level (wap_proto_t *self);
|
||||
void
|
||||
wap_proto_set_level (wap_proto_t *self, byte level);
|
||||
|
||||
// Get/set the reason field
|
||||
const char *
|
||||
wap_proto_reason (wap_proto_t *self);
|
||||
|
|
|
@ -43,11 +43,13 @@ typedef enum {
|
|||
get_info_event = 12,
|
||||
get_peer_list_event = 13,
|
||||
get_mining_status_event = 14,
|
||||
close_event = 15,
|
||||
ping_event = 16,
|
||||
expired_event = 17,
|
||||
exception_event = 18,
|
||||
settled_event = 19
|
||||
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
|
||||
} event_t;
|
||||
|
||||
// Names for state machine logging and error reporting
|
||||
|
@ -77,6 +79,8 @@ s_event_name [] = {
|
|||
"GET_INFO",
|
||||
"GET_PEER_LIST",
|
||||
"GET_MINING_STATUS",
|
||||
"SET_LOG_HASH_RATE",
|
||||
"SET_LOG_LEVEL",
|
||||
"CLOSE",
|
||||
"PING",
|
||||
"expired",
|
||||
|
@ -170,6 +174,10 @@ static void
|
|||
get_peer_list (client_t *self);
|
||||
static void
|
||||
get_mining_status (client_t *self);
|
||||
static void
|
||||
set_log_hash_rate (client_t *self);
|
||||
static void
|
||||
set_log_level (client_t *self);
|
||||
static void
|
||||
deregister_wallet (client_t *self);
|
||||
static void
|
||||
|
@ -390,6 +398,12 @@ s_protocol_event (wap_proto_t *message)
|
|||
case WAP_PROTO_GET_MINING_STATUS:
|
||||
return get_mining_status_event;
|
||||
break;
|
||||
case WAP_PROTO_SET_LOG_HASH_RATE:
|
||||
return set_log_hash_rate_event;
|
||||
break;
|
||||
case WAP_PROTO_SET_LOG_LEVEL:
|
||||
return set_log_level_event;
|
||||
break;
|
||||
case WAP_PROTO_STOP:
|
||||
return stop_event;
|
||||
break;
|
||||
|
@ -824,6 +838,42 @@ s_client_execute (s_client_t *self, event_t event)
|
|||
}
|
||||
}
|
||||
else
|
||||
if (self->event == set_log_hash_rate_event) {
|
||||
if (!self->exception) {
|
||||
// set log hash rate
|
||||
if (self->server->verbose)
|
||||
zsys_debug ("%s: $ set log hash rate", self->log_prefix);
|
||||
set_log_hash_rate (&self->client);
|
||||
}
|
||||
if (!self->exception) {
|
||||
// send SET_LOG_HASH_RATE_OK
|
||||
if (self->server->verbose)
|
||||
zsys_debug ("%s: $ send SET_LOG_HASH_RATE_OK",
|
||||
self->log_prefix);
|
||||
wap_proto_set_id (self->server->message, WAP_PROTO_SET_LOG_HASH_RATE_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 == set_log_level_event) {
|
||||
if (!self->exception) {
|
||||
// set log level
|
||||
if (self->server->verbose)
|
||||
zsys_debug ("%s: $ set log level", self->log_prefix);
|
||||
set_log_level (&self->client);
|
||||
}
|
||||
if (!self->exception) {
|
||||
// send SET_LOG_LEVEL_OK
|
||||
if (self->server->verbose)
|
||||
zsys_debug ("%s: $ send SET_LOG_LEVEL_OK",
|
||||
self->log_prefix);
|
||||
wap_proto_set_id (self->server->message, WAP_PROTO_SET_LOG_LEVEL_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
|
||||
|
|
|
@ -424,3 +424,45 @@ signal_have_get_mining_status_ok (client_t *self)
|
|||
wap_proto_thread_count (self->message),
|
||||
wap_proto_get_address (self->message));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// prepare_set_hash_log_rate_command
|
||||
//
|
||||
|
||||
static void
|
||||
prepare_set_log_hash_rate_command (client_t *self)
|
||||
{
|
||||
wap_proto_set_visible (self->message, self->args->visible);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// signal_have_set_log_hash_rate_ok
|
||||
//
|
||||
|
||||
static void
|
||||
signal_have_set_log_hash_rate_ok (client_t *self)
|
||||
{
|
||||
zsock_send (self->cmdpipe, "s8", "SET LOG HASH RATE OK",
|
||||
wap_proto_status (self->message));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// prepare_set_log_level_command
|
||||
//
|
||||
|
||||
static void
|
||||
prepare_set_log_level_command (client_t *self)
|
||||
{
|
||||
wap_proto_set_level (self->message, self->args->level);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// signal_have_set_log_level_ok
|
||||
//
|
||||
|
||||
static void
|
||||
signal_have_set_log_level_ok (client_t *self)
|
||||
{
|
||||
zsock_send (self->cmdpipe, "s8", "SET LOG LEVEL OK",
|
||||
wap_proto_status (self->message));
|
||||
}
|
||||
|
|
|
@ -63,6 +63,8 @@ struct _wap_proto_t {
|
|||
zframe_t *gray_list; // Gray list
|
||||
byte active; // Active
|
||||
uint64_t speed; // Speed
|
||||
byte visible; // Visible
|
||||
byte level; // Level
|
||||
char reason [256]; // Printable explanation
|
||||
};
|
||||
|
||||
|
@ -536,6 +538,22 @@ wap_proto_recv (wap_proto_t *self, zsock_t *input)
|
|||
}
|
||||
break;
|
||||
|
||||
case WAP_PROTO_SET_LOG_HASH_RATE:
|
||||
GET_NUMBER1 (self->visible);
|
||||
break;
|
||||
|
||||
case WAP_PROTO_SET_LOG_HASH_RATE_OK:
|
||||
GET_NUMBER8 (self->status);
|
||||
break;
|
||||
|
||||
case WAP_PROTO_SET_LOG_LEVEL:
|
||||
GET_NUMBER1 (self->level);
|
||||
break;
|
||||
|
||||
case WAP_PROTO_SET_LOG_LEVEL_OK:
|
||||
GET_NUMBER8 (self->status);
|
||||
break;
|
||||
|
||||
case WAP_PROTO_STOP:
|
||||
break;
|
||||
|
||||
|
@ -684,6 +702,18 @@ wap_proto_send (wap_proto_t *self, zsock_t *output)
|
|||
if (self->address)
|
||||
frame_size += zchunk_size (self->address);
|
||||
break;
|
||||
case WAP_PROTO_SET_LOG_HASH_RATE:
|
||||
frame_size += 1; // visible
|
||||
break;
|
||||
case WAP_PROTO_SET_LOG_HASH_RATE_OK:
|
||||
frame_size += 8; // status
|
||||
break;
|
||||
case WAP_PROTO_SET_LOG_LEVEL:
|
||||
frame_size += 1; // level
|
||||
break;
|
||||
case WAP_PROTO_SET_LOG_LEVEL_OK:
|
||||
frame_size += 8; // status
|
||||
break;
|
||||
case WAP_PROTO_ERROR:
|
||||
frame_size += 2; // status
|
||||
frame_size += 1 + strlen (self->reason);
|
||||
|
@ -856,6 +886,22 @@ wap_proto_send (wap_proto_t *self, zsock_t *output)
|
|||
PUT_NUMBER4 (0); // Empty chunk
|
||||
break;
|
||||
|
||||
case WAP_PROTO_SET_LOG_HASH_RATE:
|
||||
PUT_NUMBER1 (self->visible);
|
||||
break;
|
||||
|
||||
case WAP_PROTO_SET_LOG_HASH_RATE_OK:
|
||||
PUT_NUMBER8 (self->status);
|
||||
break;
|
||||
|
||||
case WAP_PROTO_SET_LOG_LEVEL:
|
||||
PUT_NUMBER1 (self->level);
|
||||
break;
|
||||
|
||||
case WAP_PROTO_SET_LOG_LEVEL_OK:
|
||||
PUT_NUMBER8 (self->status);
|
||||
break;
|
||||
|
||||
case WAP_PROTO_ERROR:
|
||||
PUT_NUMBER2 (self->status);
|
||||
PUT_STRING (self->reason);
|
||||
|
@ -1098,6 +1144,26 @@ wap_proto_print (wap_proto_t *self)
|
|||
zsys_debug (" address=[ ... ]");
|
||||
break;
|
||||
|
||||
case WAP_PROTO_SET_LOG_HASH_RATE:
|
||||
zsys_debug ("WAP_PROTO_SET_LOG_HASH_RATE:");
|
||||
zsys_debug (" visible=%ld", (long) self->visible);
|
||||
break;
|
||||
|
||||
case WAP_PROTO_SET_LOG_HASH_RATE_OK:
|
||||
zsys_debug ("WAP_PROTO_SET_LOG_HASH_RATE_OK:");
|
||||
zsys_debug (" status=%ld", (long) self->status);
|
||||
break;
|
||||
|
||||
case WAP_PROTO_SET_LOG_LEVEL:
|
||||
zsys_debug ("WAP_PROTO_SET_LOG_LEVEL:");
|
||||
zsys_debug (" level=%ld", (long) self->level);
|
||||
break;
|
||||
|
||||
case WAP_PROTO_SET_LOG_LEVEL_OK:
|
||||
zsys_debug ("WAP_PROTO_SET_LOG_LEVEL_OK:");
|
||||
zsys_debug (" status=%ld", (long) self->status);
|
||||
break;
|
||||
|
||||
case WAP_PROTO_STOP:
|
||||
zsys_debug ("WAP_PROTO_STOP:");
|
||||
break;
|
||||
|
@ -1247,6 +1313,18 @@ wap_proto_command (wap_proto_t *self)
|
|||
case WAP_PROTO_GET_MINING_STATUS_OK:
|
||||
return ("GET_MINING_STATUS_OK");
|
||||
break;
|
||||
case WAP_PROTO_SET_LOG_HASH_RATE:
|
||||
return ("SET_LOG_HASH_RATE");
|
||||
break;
|
||||
case WAP_PROTO_SET_LOG_HASH_RATE_OK:
|
||||
return ("SET_LOG_HASH_RATE_OK");
|
||||
break;
|
||||
case WAP_PROTO_SET_LOG_LEVEL:
|
||||
return ("SET_LOG_LEVEL");
|
||||
break;
|
||||
case WAP_PROTO_SET_LOG_LEVEL_OK:
|
||||
return ("SET_LOG_LEVEL_OK");
|
||||
break;
|
||||
case WAP_PROTO_STOP:
|
||||
return ("STOP");
|
||||
break;
|
||||
|
@ -1965,6 +2043,42 @@ wap_proto_set_speed (wap_proto_t *self, uint64_t speed)
|
|||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Get/set the visible field
|
||||
|
||||
byte
|
||||
wap_proto_visible (wap_proto_t *self)
|
||||
{
|
||||
assert (self);
|
||||
return self->visible;
|
||||
}
|
||||
|
||||
void
|
||||
wap_proto_set_visible (wap_proto_t *self, byte visible)
|
||||
{
|
||||
assert (self);
|
||||
self->visible = visible;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Get/set the level field
|
||||
|
||||
byte
|
||||
wap_proto_level (wap_proto_t *self)
|
||||
{
|
||||
assert (self);
|
||||
return self->level;
|
||||
}
|
||||
|
||||
void
|
||||
wap_proto_set_level (wap_proto_t *self, byte level)
|
||||
{
|
||||
assert (self);
|
||||
self->level = level;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Get/set the reason field
|
||||
|
||||
|
@ -2382,6 +2496,54 @@ wap_proto_test (bool verbose)
|
|||
assert (memcmp (zchunk_data (wap_proto_address (self)), "Captcha Diem", 12) == 0);
|
||||
zchunk_destroy (&get_mining_status_ok_address);
|
||||
}
|
||||
wap_proto_set_id (self, WAP_PROTO_SET_LOG_HASH_RATE);
|
||||
|
||||
wap_proto_set_visible (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_visible (self) == 123);
|
||||
}
|
||||
wap_proto_set_id (self, WAP_PROTO_SET_LOG_HASH_RATE_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_SET_LOG_LEVEL);
|
||||
|
||||
wap_proto_set_level (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_level (self) == 123);
|
||||
}
|
||||
wap_proto_set_id (self, WAP_PROTO_SET_LOG_LEVEL_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);
|
||||
|
||||
// Send twice
|
||||
|
|
|
@ -320,3 +320,25 @@ get_mining_status (client_t *self)
|
|||
{
|
||||
IPC::Daemon::get_mining_status(self->message);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// set_log_hash_rate
|
||||
//
|
||||
|
||||
static void
|
||||
set_log_hash_rate (client_t *self)
|
||||
{
|
||||
IPC::Daemon::set_log_hash_rate(self->message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// set_log_level
|
||||
//
|
||||
|
||||
static void
|
||||
set_log_level (client_t *self)
|
||||
{
|
||||
IPC::Daemon::set_log_level(self->message);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ namespace
|
|||
int invalid_request = -32600;
|
||||
int invalid_params = -32602;
|
||||
int internal_error = -32603;
|
||||
int not_mining_error = -32604;
|
||||
|
||||
RPC::Json_rpc_http_server *server = NULL;
|
||||
wap_client_t *ipc_client = NULL;
|
||||
|
@ -238,6 +239,7 @@ namespace
|
|||
response_json.GetAllocator());
|
||||
result_json.AddMember("grey_peerlist_size", wap_client_grey_peerlist_size(ipc_client),
|
||||
response_json.GetAllocator());
|
||||
result_json.AddMember("status", "OK", response_json.GetAllocator());
|
||||
|
||||
std::string response;
|
||||
construct_response_string(req, result_json, response_json, response);
|
||||
|
@ -289,6 +291,7 @@ namespace
|
|||
"Couldn't parse JSON sent by daemon.", "{}");
|
||||
}
|
||||
result_json.AddMember("gray_list", gray_list_json["peers"], allocator);
|
||||
result_json.AddMember("status", "OK", allocator);
|
||||
|
||||
std::string response;
|
||||
construct_response_string(req, result_json, response_json, response);
|
||||
|
@ -325,6 +328,7 @@ namespace
|
|||
rapidjson::Value string_value(rapidjson::kStringType);
|
||||
string_value.SetString((char*)(zchunk_data(address_chunk)), zchunk_size(address_chunk));
|
||||
result_json.AddMember("address", string_value, allocator);
|
||||
result_json.AddMember("status", "OK", allocator);
|
||||
|
||||
std::string response;
|
||||
construct_response_string(req, result_json, response_json, response);
|
||||
|
@ -333,6 +337,101 @@ namespace
|
|||
return response.length();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Implementation of 'setloghashrate' 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 setloghashrate(char *buf, int len, struct ns_rpc_request *req)
|
||||
{
|
||||
connect_to_daemon();
|
||||
if (req->params == NULL)
|
||||
{
|
||||
return ns_rpc_create_error(buf, len, req, invalid_params,
|
||||
"Parameters missing.", "{}");
|
||||
}
|
||||
|
||||
rapidjson::Document request_json;
|
||||
char request_buf[1000];
|
||||
strncpy(request_buf, req->params[0].ptr, req->params[0].len);
|
||||
request_buf[req->params[0].len] = '\0';
|
||||
if (request_json.Parse(request_buf).HasParseError())
|
||||
{
|
||||
return ns_rpc_create_error(buf, len, req, parse_error,
|
||||
"Invalid JSON passed", "{}");
|
||||
}
|
||||
|
||||
if (!request_json.HasMember("visible") || !request_json["visible"].IsBool())
|
||||
{
|
||||
return ns_rpc_create_error(buf, len, req, invalid_params,
|
||||
"Incorrect 'visible' field", "{}");
|
||||
}
|
||||
|
||||
bool visible = request_json["visible"].GetBool();
|
||||
// 0MQ server expects an integer. 1 is true, 0 is false.
|
||||
int rc = wap_client_set_log_hash_rate(ipc_client, visible ? 1 : 0);
|
||||
if (rc < 0) {
|
||||
return ns_rpc_create_error(buf, len, req, daemon_connection_error,
|
||||
"Couldn't connect to daemon.", "{}");
|
||||
}
|
||||
|
||||
if (wap_client_status(ipc_client) == IPC::STATUS_NOT_MINING) {
|
||||
return ns_rpc_create_error(buf, len, req, not_mining_error,
|
||||
"Not mining", "{}");
|
||||
}
|
||||
|
||||
return ns_rpc_create_reply(buf, len, req, "{s:s}", "status", STATUS_OK);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Implementation of 'setloglevel' 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 setloglevel(char *buf, int len, struct ns_rpc_request *req)
|
||||
{
|
||||
connect_to_daemon();
|
||||
if (req->params == NULL)
|
||||
{
|
||||
return ns_rpc_create_error(buf, len, req, invalid_params,
|
||||
"Parameters missing.", "{}");
|
||||
}
|
||||
|
||||
rapidjson::Document request_json;
|
||||
char request_buf[1000];
|
||||
strncpy(request_buf, req->params[0].ptr, req->params[0].len);
|
||||
request_buf[req->params[0].len] = '\0';
|
||||
if (request_json.Parse(request_buf).HasParseError())
|
||||
{
|
||||
return ns_rpc_create_error(buf, len, req, parse_error,
|
||||
"Invalid JSON passed", "{}");
|
||||
}
|
||||
|
||||
if (!request_json.HasMember("level") || !request_json["level"].IsNumber())
|
||||
{
|
||||
return ns_rpc_create_error(buf, len, req, invalid_params,
|
||||
"Incorrect 'level' field", "{}");
|
||||
}
|
||||
|
||||
int level = request_json["level"].GetInt();
|
||||
int rc = wap_client_set_log_level(ipc_client, level);
|
||||
if (rc < 0) {
|
||||
return ns_rpc_create_error(buf, len, req, daemon_connection_error,
|
||||
"Couldn't connect to daemon.", "{}");
|
||||
}
|
||||
|
||||
if (wap_client_status(ipc_client) == IPC::STATUS_INVALID_LOG_LEVEL) {
|
||||
return ns_rpc_create_error(buf, len, req, invalid_params,
|
||||
"Invalid log level", "{}");
|
||||
}
|
||||
|
||||
return ns_rpc_create_reply(buf, len, req, "{s:s}", "status", STATUS_OK);
|
||||
}
|
||||
|
||||
// Contains a list of method names.
|
||||
const char *method_names[] = {
|
||||
"getheight",
|
||||
|
@ -341,6 +440,8 @@ namespace
|
|||
"getinfo",
|
||||
"getpeerlist",
|
||||
"getminingstatus",
|
||||
"setloghashrate",
|
||||
"setloglevel",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -352,6 +453,8 @@ namespace
|
|||
getinfo,
|
||||
getpeerlist,
|
||||
getminingstatus,
|
||||
setloghashrate,
|
||||
setloglevel,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -414,11 +517,9 @@ namespace RPC
|
|||
server->stop();
|
||||
delete server;
|
||||
}
|
||||
std::cout << "HTTP done\n\n";
|
||||
if (ipc_client) {
|
||||
wap_client_destroy(&ipc_client);
|
||||
}
|
||||
std::cout << "IPC done\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue