Browse Source

Add an API command to list all workers

master
Con Kolivas 10 years ago
parent
commit
23d6cca7ee
  1. 43
      src/stratifier.c

43
src/stratifier.c

@ -2549,6 +2549,18 @@ out:
static worker_instance_t *get_worker(sdata_t *sdata, user_instance_t *user, const char *workername); static worker_instance_t *get_worker(sdata_t *sdata, user_instance_t *user, const char *workername);
static json_t *workerinfo(const user_instance_t *user, const worker_instance_t *worker)
{
json_t *val;
JSON_CPACK(val, "{ss,ss,sI,sf,sf,sf,sf,si,sf,si,sb}",
"user", user->username, "worker", worker->workername, "id", user->id,
"dsps1", worker->dsps1, "dsps5", worker->dsps5, "dsps60", worker->dsps60,
"dsps1440", worker->dsps1440, "lastshare", worker->last_share.tv_sec,
"bestdiff", worker->best_diff, "mindiff", worker->mindiff, "idle", worker->idle);
return val;
}
static void getworker(sdata_t *sdata, const char *buf, int *sockd) static void getworker(sdata_t *sdata, const char *buf, int *sockd)
{ {
char *tmp, *username, *workername = NULL; char *tmp, *username, *workername = NULL;
@ -2574,17 +2586,34 @@ static void getworker(sdata_t *sdata, const char *buf, int *sockd)
username = strsep(&tmp, "._"); username = strsep(&tmp, "._");
user = get_user(sdata, username); user = get_user(sdata, username);
worker = get_worker(sdata, user, workername); worker = get_worker(sdata, user, workername);
JSON_CPACK(val, "{ss,ss,sI,sf,sf,sf,sf,si,sf,si,sb}", val = workerinfo(user, worker);
"user", username, "worker", workername, "id", user->id,
"dsps1", worker->dsps1, "dsps5", worker->dsps5, "dsps60", worker->dsps60,
"dsps1440", worker->dsps1440, "lastshare", worker->last_share.tv_sec,
"bestdiff", worker->best_diff, "mindiff", worker->mindiff, "idle", worker->idle);
out: out:
free(workername); free(workername);
send_api_response(val, *sockd); send_api_response(val, *sockd);
_Close(sockd); _Close(sockd);
} }
static void getworkers(sdata_t *sdata, int *sockd)
{
json_t *val = NULL, *worker_arr;
worker_instance_t *worker;
user_instance_t *user;
worker_arr = json_array();
ck_rlock(&sdata->instance_lock);
for (user = sdata->user_instances; user; user = user->hh.next) {
DL_FOREACH(user->worker_instances, worker) {
json_array_append_new(worker_arr, workerinfo(user, worker));
}
}
ck_runlock(&sdata->instance_lock);
JSON_CPACK(val, "{so}", "workers", worker_arr);
send_api_response(val, *sockd);
_Close(sockd);
}
static json_t *clientinfo(const stratum_instance_t *client) static json_t *clientinfo(const stratum_instance_t *client)
{ {
json_t *val = json_object(); json_t *val = json_object();
@ -2950,6 +2979,10 @@ retry:
getclients(sdata, &sockd); getclients(sdata, &sockd);
goto retry; goto retry;
} }
if (cmdmatch(buf, "workers")) {
getworkers(sdata, &sockd);
goto retry;
}
if (cmdmatch(buf, "getclient")) { if (cmdmatch(buf, "getclient")) {
getclient(sdata, buf + 10, &sockd); getclient(sdata, buf + 10, &sockd);
goto retry; goto retry;

Loading…
Cancel
Save