diff --git a/cpu-miner.c b/cpu-miner.c index e6ee4c7e7..230858a8f 100644 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -137,6 +137,7 @@ static const char *algo_names[] = { bool opt_debug = false; bool opt_protocol = false; +static bool opt_keepalive = false ; static bool opt_benchmark = false; bool opt_redirect = true; bool want_longpoll = true; @@ -207,6 +208,7 @@ Options:\n\ --cert=FILE certificate for mining server using SSL\n\ -x, --proxy=[PROTOCOL://]HOST[:PORT] connect through a proxy\n\ -t, --threads=N number of miner threads (default: number of processors)\n\ + -k, --keepalive Send keepalived for prevent timeout (need pool support features)\n\ -r, --retries=N number of times to retry if a network call fails\n\ (default: retry indefinitely)\n\ -R, --retry-pause=N time to pause between retries, in seconds (default: 30)\n\ @@ -241,7 +243,7 @@ static char const short_options[] = #ifdef HAVE_SYSLOG_H "S" #endif - "a:c:Dhp:Px:qr:R:s:t:T:o:u:O:V"; + "a:c:Dhp:Px:kqr:R:s:t:T:o:u:O:V"; static struct option const options[] = { { "algo", 1, NULL, 'a' }, @@ -253,6 +255,7 @@ static struct option const options[] = { { "config", 1, NULL, 'c' }, { "debug", 0, NULL, 'D' }, { "help", 0, NULL, 'h' }, + { "keepalive" , 0 , NULL ,'k'}, { "no-longpoll", 0, NULL, 1003 }, { "no-redirect", 0, NULL, 1009 }, { "no-stratum", 0, NULL, 1007 }, @@ -1047,7 +1050,6 @@ static void *miner_thread(void *userdata) { thr_id % num_processors); affine_to_cpu(thr_id, thr_id % num_processors); }*/ - persistentctx = persistentctxs[thr_id]; if(!persistentctx && opt_algo == ALGO_CRYPTONIGHT) { @@ -1328,8 +1330,12 @@ static bool stratum_handle_response(char *buf) { if(jsonrpc_2) { json_t *status = json_object_get(res_val, "status"); + const char *s = json_string_value(status); + if ( !strcmp(s, "KEEPALIVED") ) { + applog(LOG_INFO, "Keepalived receveid"); + goto out; + } if(status) { - const char *s = json_string_value(status); valid = !strcmp(s, "OK") && json_is_null(err_val); } else { valid = json_is_null(err_val); @@ -1405,11 +1411,14 @@ static void *stratum_thread(void *userdata) { } } } - - if (!stratum_socket_full(&stratum, 600)) { - applog(LOG_ERR, "Stratum connection timed out"); - s = NULL; - } else + if ( opt_keepalive && !stratum_socket_full(&stratum, 90)) { + applog(LOG_INFO, "Keepalived send...."); + stratum_keepalived(&stratum,rpc2_id); + } + if (!stratum_socket_full(&stratum, 300)) { + applog(LOG_ERR, "Stratum connection timed out"); + s = NULL; + } else s = stratum_recv_line(&stratum); if (!s) { stratum_disconnect(&stratum); diff --git a/miner.h b/miner.h index ec4ed74d1..c9607b370 100644 --- a/miner.h +++ b/miner.h @@ -277,6 +277,7 @@ struct stratum_ctx { pthread_mutex_t work_lock; }; +bool stratum_keepalived(struct stratum_ctx *sctx , const char *rpc2_id); bool stratum_socket_full(struct stratum_ctx *sctx, int timeout); bool stratum_send_line(struct stratum_ctx *sctx, char *s); char *stratum_recv_line(struct stratum_ctx *sctx); diff --git a/util.c b/util.c index 7251cb329..7a7e222a3 100644 --- a/util.c +++ b/util.c @@ -925,6 +925,33 @@ bool stratum_subscribe(struct stratum_ctx *sctx) } return ret; +} + +bool stratum_keepalived(struct stratum_ctx *sctx, const char *rpc2_id) { + + + json_t *val = NULL, *res_val, *err_val; + char *s, *sret; + json_error_t err; + bool ret = false; + + if(jsonrpc_2) { + s = malloc(300 + strlen(rpc2_id)); + snprintf(s, 128, "{\"method\": \"keepalived\", \"params\": {\"id\": \"%s\"}, \"id\":1}\r\n", rpc2_id); + } else { + return true ; + + } + if (!stratum_send_line(sctx, s)) + goto out; + ret = true; +out: + free(s); + return ret; + + + + } bool stratum_authorize(struct stratum_ctx *sctx, const char *user, const char *pass)