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