diff --git a/src/connector.c b/src/connector.c index ea3d84d4..e9935748 100644 --- a/src/connector.c +++ b/src/connector.c @@ -899,6 +899,18 @@ static void send_client(cdata_t *cdata, const int64_t id, char *buf) free(buf); return; } + if (ckp->node) { + json_t *val = json_loads(buf, 0, NULL); + char *msg; + + json_object_set_new_nocheck(val, "client_id", json_integer(client->id)); + json_object_set_new_nocheck(val, "address", json_string(client->address_name)); + json_object_set_new_nocheck(val, "server", json_integer(client->server)); + msg = json_dumps(val, 0); + json_decref(val); + send_proc(ckp->stratifier, msg); + free(msg); + } if (ckp->redirector && !client->redirected) test_redirector_shares(ckp, client, buf); } @@ -936,7 +948,7 @@ static void passthrough_client(cdata_t *cdata, client_instance_t *client) send_client(cdata, client->id, buf); } -static void process_client_msg(ckpool_t *ckp, cdata_t *cdata, const char *buf) +static void process_client_msg(cdata_t *cdata, const char *buf) { int64_t client_id; json_t *json_msg; @@ -1056,7 +1068,7 @@ retry: /* The bulk of the messages will be json messages to send to clients * so look for them first. */ if (likely(buf[0] == '{')) { - process_client_msg(ckp, cdata, buf); + process_client_msg(cdata, buf); } else if (cmdmatch(buf, "dropclient")) { client_instance_t *client; diff --git a/src/generator.c b/src/generator.c index e46a4746..36cd2647 100644 --- a/src/generator.c +++ b/src/generator.c @@ -1980,27 +1980,6 @@ static void reconnect_proxy(proxy_instance_t *proxi) create_pthread(&pth, proxy_reconnect, proxi); } -static int node_msg_type(json_t *val) -{ - int i, ret = -1; - char *node_msg; - - if (!val) - goto out; - if (!json_get_string(&node_msg, val, "node.method")) - goto out; - for (i = 0; i < SM_NONE; i++) { - if (!strcmp(node_msg, stratum_msgs[i])) { - ret = i; - LOGWARNING("Got node method %d:%s", i, node_msg); - break; - } - } - json_object_del(val, "node.method"); -out: - return ret; -} - /* For receiving messages from an upstream pool to pass downstream. Responsible * for setting up the connection and testing pool is live. */ static void *passthrough_recv(void *arg) @@ -2043,10 +2022,6 @@ static void *passthrough_recv(void *arg) Close(cs->fd); continue; } - if (ckp->node) { - json_t *val = json_loads(cs->buf, 0, NULL); - int msg_type = node_msg_type(val); - } /* Simply forward the message on, as is, to the connector to * process. Possibly parse parameters sent by upstream pool * here */ diff --git a/src/stratifier.c b/src/stratifier.c index 8a2abab4..d30877ee 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -5038,9 +5038,6 @@ static void parse_method(ckpool_t *ckp, sdata_t *sdata, stratum_instance_t *clie return; } - if (ckp->node) - return; - if (cmdmatch(method, "mining.subscribe")) { json_t *val, *result_val; @@ -5142,6 +5139,27 @@ static void free_smsg(smsg_t *msg) free(msg); } +static int node_msg_type(json_t *val) +{ + int i, ret = -1; + char *node_msg; + + if (!val) + goto out; + if (!json_get_string(&node_msg, val, "node.method")) + goto out; + for (i = 0; i < SM_NONE; i++) { + if (!strcmp(node_msg, stratum_msgs[i])) { + ret = i; + LOGWARNING("Got node method %d:%s", i, node_msg); + break; + } + } + json_object_del(val, "node.method"); +out: + return ret; +} + /* Entered with client holding ref count */ static void parse_instance_msg(ckpool_t *ckp, sdata_t *sdata, smsg_t *msg, stratum_instance_t *client) { @@ -5185,7 +5203,15 @@ 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"); goto out; } - parse_method(ckp, sdata, client, client_id, id_val, method, params); + if (ckp->node) { + 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: free_smsg(msg); }