Browse Source

Identify all node message types in the stratifier

master
Con Kolivas 9 years ago
parent
commit
5ddfcdb14e
  1. 4
      src/connector.c
  2. 44
      src/stratifier.c

4
src/connector.c

@ -504,10 +504,10 @@ reparse:
* do this unlocked as the occasional false negative can be * do this unlocked as the occasional false negative can be
* filtered by the stratifier. */ * filtered by the stratifier. */
if (likely(!client->invalid)) { if (likely(!client->invalid)) {
if (!ckp->passthrough || ckp->node)
send_proc(ckp->stratifier, s);
if (ckp->passthrough) if (ckp->passthrough)
send_proc(ckp->generator, s); send_proc(ckp->generator, s);
else
send_proc(ckp->stratifier, s);
} }
free(s); free(s);

44
src/stratifier.c

@ -5142,24 +5142,45 @@ static void free_smsg(smsg_t *msg)
static int node_msg_type(json_t *val) static int node_msg_type(json_t *val)
{ {
int i, ret = -1; int i, ret = -1;
char *node_msg; char *method;
if (!val) if (!val)
goto out; goto out;
if (!json_get_string(&node_msg, val, "node.method")) if (!json_get_string(&method, val, "node.method"))
goto out; goto out;
for (i = 0; i < SM_NONE; i++) { for (i = 0; i < SM_NONE; i++) {
if (!strcmp(node_msg, stratum_msgs[i])) { if (!strcmp(method, stratum_msgs[i])) {
ret = i; ret = i;
LOGWARNING("Got node method %d:%s", i, node_msg); LOGWARNING("Got node method %d:%s", i, method);
break; break;
} }
} }
json_object_del(val, "node.method"); json_object_del(val, "node.method");
out: out:
if (ret < 0 && json_get_string(&method, val, "method")) {
if (!safecmp(method, "mining.subscribe"))
ret = SM_SUBSCRIBE;
else if (!safecmp(method, "mining.submit"))
ret = SM_SHARE;
else if (cmdmatch(method, "mining.auth"))
ret = SM_AUTH;
else if (cmdmatch(method, "mining.get"))
ret = SM_TXNS;
}
return ret; return ret;
} }
/* Entered with client holding ref count */
static void parse_node_msg(json_t *val, const char *buf, stratum_instance_t *client)
{
int msg_type = node_msg_type(val);
if (msg_type > -1)
LOGWARNING("Got node method %d:%s", msg_type, stratum_msgs[msg_type]);
else
LOGWARNING("Missing node method from %s", buf);
}
/* Entered with client holding ref count */ /* Entered with client holding ref count */
static void parse_instance_msg(ckpool_t *ckp, sdata_t *sdata, smsg_t *msg, stratum_instance_t *client) static void parse_instance_msg(ckpool_t *ckp, sdata_t *sdata, smsg_t *msg, stratum_instance_t *client)
{ {
@ -5203,15 +5224,7 @@ static void parse_instance_msg(ckpool_t *ckp, sdata_t *sdata, smsg_t *msg, strat
send_json_err(sdata, client_id, id_val, "-1:params not found"); send_json_err(sdata, client_id, id_val, "-1:params not found");
goto out; goto out;
} }
if (ckp->node) { parse_method(ckp, sdata, client, client_id, id_val, method, params);
int msg_type = node_msg_type(val);
if (msg_type > -1)
LOGWARNING("Got node method %d:%s", msg_type, stratum_msgs[msg_type]);
else
LOGWARNING("Missing node method");
} else
parse_method(ckp, sdata, client, client_id, id_val, method, params);
out: out:
free_smsg(msg); free_smsg(msg);
} }
@ -5288,7 +5301,10 @@ static void srecv_process(ckpool_t *ckp, char *buf)
if (unlikely(noid)) if (unlikely(noid))
LOGINFO("Stratifier added instance %"PRId64" server %d", client->id, server); LOGINFO("Stratifier added instance %"PRId64" server %d", client->id, server);
parse_instance_msg(ckp, sdata, msg, client); if (ckp->node)
parse_node_msg(msg->json_msg, buf, client);
else
parse_instance_msg(ckp, sdata, msg, client);
dec_instance_ref(sdata, client); dec_instance_ref(sdata, client);
out: out:
free(buf); free(buf);

Loading…
Cancel
Save