Browse Source

Use the cmdmatch function for commands in the stratifier

master
Con Kolivas 10 years ago
parent
commit
772315e417
  1. 1
      src/libckpool.c
  2. 30
      src/stratifier.c

1
src/libckpool.c

@ -1098,6 +1098,7 @@ bool cmdmatch(const char *buf, const char *cmd)
return !strncasecmp(buf, cmd, cmdlen); return !strncasecmp(buf, cmd, cmdlen);
} }
static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/* Return a malloced string of *src encoded into mime base 64 */ /* Return a malloced string of *src encoded into mime base 64 */

30
src/stratifier.c

@ -542,7 +542,7 @@ static void update_base(ckpool_t *ckp)
LOGWARNING("Failed to get base from generator in update_base"); LOGWARNING("Failed to get base from generator in update_base");
return; return;
} }
if (unlikely(!strncasecmp(buf, "failed", 6))) { if (unlikely(cmdmatch(buf, "failed"))) {
LOGWARNING("Generator returned failure in update_base"); LOGWARNING("Generator returned failure in update_base");
return; return;
} }
@ -1020,7 +1020,7 @@ retry:
LOGWARNING("Failed to get message in stratum_loop"); LOGWARNING("Failed to get message in stratum_loop");
goto retry; goto retry;
} }
if (!strncasecmp(buf, "ping", 4)) { if (cmdmatch(buf, "ping")) {
LOGDEBUG("Stratifier received ping request"); LOGDEBUG("Stratifier received ping request");
send_unix_msg(sockd, "pong"); send_unix_msg(sockd, "pong");
close(sockd); close(sockd);
@ -1029,21 +1029,21 @@ retry:
close(sockd); close(sockd);
LOGDEBUG("Stratifier received request: %s", buf); LOGDEBUG("Stratifier received request: %s", buf);
if (!strncasecmp(buf, "shutdown", 8)) { if (cmdmatch(buf, "shutdown")) {
ret = 0; ret = 0;
goto out; goto out;
} else if (!strncasecmp(buf, "update", 6)) { } else if (cmdmatch(buf, "update")) {
update_base(ckp); update_base(ckp);
} else if (!strncasecmp(buf, "subscribe", 9)) { } else if (cmdmatch(buf, "subscribe")) {
/* Proxifier has a new subscription */ /* Proxifier has a new subscription */
if (!update_subscribe(ckp)) if (!update_subscribe(ckp))
goto out; goto out;
} else if (!strncasecmp(buf, "notify", 6)) { } else if (cmdmatch(buf, "notify")) {
/* Proxifier has a new notify ready */ /* Proxifier has a new notify ready */
update_notify(ckp); update_notify(ckp);
} else if (!strncasecmp(buf, "diff", 4)) { } else if (cmdmatch(buf, "diff")) {
update_diff(ckp); update_diff(ckp);
} else if (!strncasecmp(buf, "dropclient", 10)) { } else if (cmdmatch(buf, "dropclient")) {
int client_id; int client_id;
ret = sscanf(buf, "dropclient=%d", &client_id); ret = sscanf(buf, "dropclient=%d", &client_id);
@ -1051,9 +1051,9 @@ retry:
LOGDEBUG("Stratifier failed to parse dropclient command: %s", buf); LOGDEBUG("Stratifier failed to parse dropclient command: %s", buf);
else else
drop_client(client_id); drop_client(client_id);
} else if (!strncasecmp(buf, "block", 5)) { } else if (cmdmatch(buf, "block")) {
block_solve(ckp); block_solve(ckp);
} else if (!strncasecmp(buf, "loglevel", 8)) { } else if (cmdmatch(buf, "loglevel")) {
sscanf(buf, "loglevel=%d", &ckp->loglevel); sscanf(buf, "loglevel=%d", &ckp->loglevel);
} else { } else {
json_t *val = json_loads(buf, 0, NULL); json_t *val = json_loads(buf, 0, NULL);
@ -1079,7 +1079,7 @@ static void *blockupdate(void *arg)
pthread_detach(pthread_self()); pthread_detach(pthread_self());
rename_proc("blockupdate"); rename_proc("blockupdate");
buf = send_recv_proc(ckp->generator, "getbest"); buf = send_recv_proc(ckp->generator, "getbest");
if (buf && strncasecmp(buf, "Failed", 6)) if (!cmdmatch(buf, "failed"))
sprintf(request, "getbest"); sprintf(request, "getbest");
else else
sprintf(request, "getlast"); sprintf(request, "getlast");
@ -1088,7 +1088,7 @@ static void *blockupdate(void *arg)
while (42) { while (42) {
dealloc(buf); dealloc(buf);
buf = send_recv_proc(ckp->generator, request); buf = send_recv_proc(ckp->generator, request);
if (safecmp(buf, hash) && strncasecmp(buf, "Failed", 6)) { if (safecmp(buf, hash) && !cmdmatch(buf, "failed")) {
strcpy(hash, buf); strcpy(hash, buf);
LOGNOTICE("Block hash changed to %s", hash); LOGNOTICE("Block hash changed to %s", hash);
send_proc(ckp->stratifier, "update"); send_proc(ckp->stratifier, "update");
@ -1899,7 +1899,7 @@ static void parse_method(const int client_id, json_t *id_val, json_t *method_val
/* Random broken clients send something not an integer as the id so we copy /* Random broken clients send something not an integer as the id so we copy
* the json item for id_val as is for the response. */ * the json item for id_val as is for the response. */
method = json_string_value(method_val); method = json_string_value(method_val);
if (!strncasecmp(method, "mining.subscribe", 16)) { if (cmdmatch(method, "mining.subscribe")) {
json_t *val, *result_val = parse_subscribe(client_id, params_val); json_t *val, *result_val = parse_subscribe(client_id, params_val);
if (!result_val) if (!result_val)
@ -1922,7 +1922,7 @@ static void parse_method(const int client_id, json_t *id_val, json_t *method_val
return; return;
} }
if (!strncasecmp(method, "mining.auth", 11)) { if (cmdmatch(method, "mining.auth")) {
json_params_t *jp = create_json_params(client_id, params_val, id_val, address); json_params_t *jp = create_json_params(client_id, params_val, id_val, address);
ckmsgq_add(sauthq, jp); ckmsgq_add(sauthq, jp);
@ -1942,7 +1942,7 @@ static void parse_method(const int client_id, json_t *id_val, json_t *method_val
return; return;
} }
if (!strncasecmp(method, "mining.submit", 13)) { if (cmdmatch(method, "mining.submit")) {
json_params_t *jp = create_json_params(client_id, params_val, id_val, address); json_params_t *jp = create_json_params(client_id, params_val, id_val, address);
ckmsgq_add(sshareq, jp); ckmsgq_add(sshareq, jp);

Loading…
Cancel
Save