|
|
@ -2983,13 +2983,18 @@ static void get_poolstats(sdata_t *sdata, int *sockd) |
|
|
|
|
|
|
|
|
|
|
|
static int stratum_loop(ckpool_t *ckp, proc_instance_t *pi) |
|
|
|
static int stratum_loop(ckpool_t *ckp, proc_instance_t *pi) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int sockd, ret = 0, selret = 0; |
|
|
|
|
|
|
|
sdata_t *sdata = ckp->data; |
|
|
|
sdata_t *sdata = ckp->data; |
|
|
|
unixsock_t *us = &pi->us; |
|
|
|
unix_msg_t *umsg = NULL; |
|
|
|
tv_t start_tv = {0, 0}; |
|
|
|
tv_t start_tv = {0, 0}; |
|
|
|
char *buf = NULL; |
|
|
|
int ret = 0; |
|
|
|
|
|
|
|
char *buf; |
|
|
|
|
|
|
|
|
|
|
|
retry: |
|
|
|
retry: |
|
|
|
|
|
|
|
if (umsg) { |
|
|
|
|
|
|
|
free(umsg->buf); |
|
|
|
|
|
|
|
dealloc(umsg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
do { |
|
|
|
do { |
|
|
|
double tdiff; |
|
|
|
double tdiff; |
|
|
|
tv_t end_tv; |
|
|
|
tv_t end_tv; |
|
|
@ -3008,41 +3013,29 @@ retry: |
|
|
|
broadcast_ping(sdata); |
|
|
|
broadcast_ping(sdata); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
selret = wait_read_select(us->sockd, 5); |
|
|
|
|
|
|
|
if (!selret && !ping_main(ckp)) { |
|
|
|
|
|
|
|
LOGEMERG("Generator failed to ping main process, exiting"); |
|
|
|
|
|
|
|
ret = 1; |
|
|
|
|
|
|
|
goto out; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} while (selret < 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sockd = accept(us->sockd, NULL, NULL); |
|
|
|
umsg = get_unix_msg(pi); |
|
|
|
if (sockd < 0) { |
|
|
|
if (unlikely(!umsg &&!ping_main(ckp))) { |
|
|
|
LOGERR("Failed to accept on stratifier socket, exiting"); |
|
|
|
LOGEMERG("Stratifier failed to ping main process, exiting"); |
|
|
|
ret = 1; |
|
|
|
ret = 1; |
|
|
|
goto out; |
|
|
|
goto out; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} while (!umsg); |
|
|
|
|
|
|
|
|
|
|
|
dealloc(buf); |
|
|
|
buf = umsg->buf; |
|
|
|
buf = recv_unix_msg(sockd); |
|
|
|
|
|
|
|
if (unlikely(!buf)) { |
|
|
|
|
|
|
|
Close(sockd); |
|
|
|
|
|
|
|
LOGWARNING("Failed to get message in stratum_loop"); |
|
|
|
|
|
|
|
goto retry; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (likely(buf[0] == '{')) { |
|
|
|
if (likely(buf[0] == '{')) { |
|
|
|
/* The bulk of the messages will be received json from the
|
|
|
|
/* The bulk of the messages will be received json from the
|
|
|
|
* connector so look for this first. The srecv_process frees |
|
|
|
* connector so look for this first. The srecv_process frees |
|
|
|
* the buf heap ram */ |
|
|
|
* the buf heap ram */ |
|
|
|
Close(sockd); |
|
|
|
Close(umsg->sockd); |
|
|
|
ckmsgq_add(sdata->srecvs, buf); |
|
|
|
ckmsgq_add(sdata->srecvs, umsg->buf); |
|
|
|
buf = NULL; |
|
|
|
umsg->buf = NULL; |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "ping")) { |
|
|
|
if (cmdmatch(buf, "ping")) { |
|
|
|
LOGDEBUG("Stratifier received ping request"); |
|
|
|
LOGDEBUG("Stratifier received ping request"); |
|
|
|
send_unix_msg(sockd, "pong"); |
|
|
|
send_unix_msg(umsg->sockd, "pong"); |
|
|
|
Close(sockd); |
|
|
|
Close(umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "stats")) { |
|
|
|
if (cmdmatch(buf, "stats")) { |
|
|
@ -3050,69 +3043,69 @@ retry: |
|
|
|
|
|
|
|
|
|
|
|
LOGDEBUG("Stratifier received stats request"); |
|
|
|
LOGDEBUG("Stratifier received stats request"); |
|
|
|
msg = stratifier_stats(ckp, sdata); |
|
|
|
msg = stratifier_stats(ckp, sdata); |
|
|
|
send_unix_msg(sockd, msg); |
|
|
|
send_unix_msg(umsg->sockd, msg); |
|
|
|
Close(sockd); |
|
|
|
Close(umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
/* Parse API commands here to return a message to sockd */ |
|
|
|
/* Parse API commands here to return a message to sockd */ |
|
|
|
if (cmdmatch(buf, "clients")) { |
|
|
|
if (cmdmatch(buf, "clients")) { |
|
|
|
getclients(sdata, &sockd); |
|
|
|
getclients(sdata, &umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "workers")) { |
|
|
|
if (cmdmatch(buf, "workers")) { |
|
|
|
getworkers(sdata, &sockd); |
|
|
|
getworkers(sdata, &umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "users")) { |
|
|
|
if (cmdmatch(buf, "users")) { |
|
|
|
getusers(sdata, &sockd); |
|
|
|
getusers(sdata, &umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "getclient")) { |
|
|
|
if (cmdmatch(buf, "getclient")) { |
|
|
|
getclient(sdata, buf + 10, &sockd); |
|
|
|
getclient(sdata, buf + 10, &umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "getuser")) { |
|
|
|
if (cmdmatch(buf, "getuser")) { |
|
|
|
getuser(sdata, buf + 8, &sockd); |
|
|
|
getuser(sdata, buf + 8, &umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "getworker")) { |
|
|
|
if (cmdmatch(buf, "getworker")) { |
|
|
|
getworker(sdata, buf + 10, &sockd); |
|
|
|
getworker(sdata, buf + 10, &umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "userclients")) { |
|
|
|
if (cmdmatch(buf, "userclients")) { |
|
|
|
userclients(sdata, buf + 12, &sockd); |
|
|
|
userclients(sdata, buf + 12, &umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "workerclients")) { |
|
|
|
if (cmdmatch(buf, "workerclients")) { |
|
|
|
workerclients(sdata, buf + 14, &sockd); |
|
|
|
workerclients(sdata, buf + 14, &umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "getproxy")) { |
|
|
|
if (cmdmatch(buf, "getproxy")) { |
|
|
|
getproxy(sdata, buf + 9, &sockd); |
|
|
|
getproxy(sdata, buf + 9, &umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "setproxy")) { |
|
|
|
if (cmdmatch(buf, "setproxy")) { |
|
|
|
setproxy(sdata, buf + 9, &sockd); |
|
|
|
setproxy(sdata, buf + 9, &umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "poolstats")) { |
|
|
|
if (cmdmatch(buf, "poolstats")) { |
|
|
|
get_poolstats(sdata, &sockd); |
|
|
|
get_poolstats(sdata, &umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "proxyinfo")) { |
|
|
|
if (cmdmatch(buf, "proxyinfo")) { |
|
|
|
proxyinfo(sdata, buf + 10, &sockd); |
|
|
|
proxyinfo(sdata, buf + 10, &umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "ucinfo")) { |
|
|
|
if (cmdmatch(buf, "ucinfo")) { |
|
|
|
user_clientinfo(sdata, buf + 7, &sockd); |
|
|
|
user_clientinfo(sdata, buf + 7, &umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cmdmatch(buf, "wcinfo")) { |
|
|
|
if (cmdmatch(buf, "wcinfo")) { |
|
|
|
worker_clientinfo(sdata, buf + 7, &sockd); |
|
|
|
worker_clientinfo(sdata, buf + 7, &umsg->sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Close(sockd); |
|
|
|
Close(umsg->sockd); |
|
|
|
LOGDEBUG("Stratifier received request: %s", buf); |
|
|
|
LOGDEBUG("Stratifier received request: %s", buf); |
|
|
|
if (cmdmatch(buf, "shutdown")) { |
|
|
|
if (cmdmatch(buf, "shutdown")) { |
|
|
|
ret = 0; |
|
|
|
ret = 0; |
|
|
@ -3160,7 +3153,6 @@ retry: |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
|
|
|
|
|
|
|
|
out: |
|
|
|
out: |
|
|
|
dealloc(buf); |
|
|
|
|
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -6011,6 +6003,8 @@ int stratifier(proc_instance_t *pi) |
|
|
|
mutex_init(&sdata->share_lock); |
|
|
|
mutex_init(&sdata->share_lock); |
|
|
|
mutex_init(&sdata->block_lock); |
|
|
|
mutex_init(&sdata->block_lock); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
create_unix_receiver(pi); |
|
|
|
|
|
|
|
|
|
|
|
LOGWARNING("%s stratifier ready", ckp->name); |
|
|
|
LOGWARNING("%s stratifier ready", ckp->name); |
|
|
|
|
|
|
|
|
|
|
|
ret = stratum_loop(ckp, pi); |
|
|
|
ret = stratum_loop(ckp, pi); |
|
|
|