Browse Source

Optimise method parsing for the common case of shares first and do not allow clients to try and subscribe or authorise twice

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

43
src/stratifier.c

@ -3285,12 +3285,25 @@ static void parse_method(sdata_t *sdata, stratum_instance_t *client, const int64
const char *method; const char *method;
char buf[256]; char buf[256];
/* 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
* the json item for id_val as is for the response. */ * copy the json item for id_val as is for the response. By far the
* most common messages will be shares so look for those first */
method = json_string_value(method_val); method = json_string_value(method_val);
if (likely(cmdmatch(method, "mining.submit") && client->authorised)) {
json_params_t *jp = create_json_params(client_id, method_val, params_val, id_val, address);
ckmsgq_add(sdata->sshareq, jp);
return;
}
if (cmdmatch(method, "mining.subscribe")) { if (cmdmatch(method, "mining.subscribe")) {
json_t *val, *result_val = parse_subscribe(client, client_id, params_val); json_t *val, *result_val;
if (unlikely(client->subscribed)) {
LOGNOTICE("Client %ld trying to subscribe twice", client_id);
return;
}
result_val = parse_subscribe(client, client_id, params_val);
/* Shouldn't happen, sanity check */ /* Shouldn't happen, sanity check */
if (unlikely(!result_val)) { if (unlikely(!result_val)) {
LOGWARNING("parse_subscribe returned NULL result_val"); LOGWARNING("parse_subscribe returned NULL result_val");
@ -3323,9 +3336,22 @@ static void parse_method(sdata_t *sdata, stratum_instance_t *client, const int64
return; return;
} }
if (cmdmatch(method, "mining.auth") && client->subscribed) { /* We should only accept subscribed requests from here on */
json_params_t *jp = create_json_params(client_id, method_val, params_val, id_val, address); if (!client->subscribed) {
LOGINFO("Dropping unsubscribed client %ld", client_id);
snprintf(buf, 255, "dropclient=%ld", client_id);
send_proc(client->ckp->connector, buf);
return;
}
if (cmdmatch(method, "mining.auth")) {
json_params_t *jp;
if (unlikely(client->authorised)) {
LOGNOTICE("Client %ld trying to authorise twice", client_id);
return;
}
jp = create_json_params(client_id, method_val, params_val, id_val, address);
ckmsgq_add(sdata->sauthq, jp); ckmsgq_add(sdata->sauthq, jp);
return; return;
} }
@ -3341,13 +3367,6 @@ static void parse_method(sdata_t *sdata, stratum_instance_t *client, const int64
return; return;
} }
if (cmdmatch(method, "mining.submit")) {
json_params_t *jp = create_json_params(client_id, method_val, params_val, id_val, address);
ckmsgq_add(sdata->sshareq, jp);
return;
}
if (cmdmatch(method, "mining.suggest")) { if (cmdmatch(method, "mining.suggest")) {
suggest_diff(client, method, params_val); suggest_diff(client, method, params_val);
return; return;

Loading…
Cancel
Save