Browse Source

Move message type detection to stratifier

master
Con Kolivas 9 years ago
parent
commit
50c9b5ecd2
  1. 16
      src/connector.c
  2. 25
      src/generator.c
  3. 34
      src/stratifier.c

16
src/connector.c

@ -899,6 +899,18 @@ static void send_client(cdata_t *cdata, const int64_t id, char *buf)
free(buf); free(buf);
return; 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) if (ckp->redirector && !client->redirected)
test_redirector_shares(ckp, client, buf); 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); 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; int64_t client_id;
json_t *json_msg; json_t *json_msg;
@ -1056,7 +1068,7 @@ retry:
/* The bulk of the messages will be json messages to send to clients /* The bulk of the messages will be json messages to send to clients
* so look for them first. */ * so look for them first. */
if (likely(buf[0] == '{')) { if (likely(buf[0] == '{')) {
process_client_msg(ckp, cdata, buf); process_client_msg(cdata, buf);
} else if (cmdmatch(buf, "dropclient")) { } else if (cmdmatch(buf, "dropclient")) {
client_instance_t *client; client_instance_t *client;

25
src/generator.c

@ -1980,27 +1980,6 @@ static void reconnect_proxy(proxy_instance_t *proxi)
create_pthread(&pth, proxy_reconnect, 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 receiving messages from an upstream pool to pass downstream. Responsible
* for setting up the connection and testing pool is live. */ * for setting up the connection and testing pool is live. */
static void *passthrough_recv(void *arg) static void *passthrough_recv(void *arg)
@ -2043,10 +2022,6 @@ static void *passthrough_recv(void *arg)
Close(cs->fd); Close(cs->fd);
continue; 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 /* Simply forward the message on, as is, to the connector to
* process. Possibly parse parameters sent by upstream pool * process. Possibly parse parameters sent by upstream pool
* here */ * here */

34
src/stratifier.c

@ -5038,9 +5038,6 @@ static void parse_method(ckpool_t *ckp, sdata_t *sdata, stratum_instance_t *clie
return; return;
} }
if (ckp->node)
return;
if (cmdmatch(method, "mining.subscribe")) { if (cmdmatch(method, "mining.subscribe")) {
json_t *val, *result_val; json_t *val, *result_val;
@ -5142,6 +5139,27 @@ static void free_smsg(smsg_t *msg)
free(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 */ /* 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)
{ {
@ -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"); send_json_err(sdata, client_id, id_val, "-1:params not found");
goto out; 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: out:
free_smsg(msg); free_smsg(msg);
} }

Loading…
Cancel
Save