Skip to content

Commit

Permalink
Add function keepalive
Browse files Browse the repository at this point in the history
  • Loading branch information
administrator committed Mar 21, 2016
1 parent 8393e03 commit 0c8aedb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
25 changes: 17 additions & 8 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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\
Expand Down Expand Up @@ -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' },
Expand All @@ -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 },
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 27 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0c8aedb

Please sign in to comment.