Browse Source

Remove attempted share identification from generator in redirector mode as it hasn't enough information

master
Con Kolivas 10 years ago
parent
commit
35b81bad17
  1. 73
      src/generator.c

73
src/generator.c

@ -1498,7 +1498,7 @@ static void account_shares(proxy_instance_t *proxy, const double diff, const boo
/* Returns zero if it is not recognised as a share, 1 if it is a valid share /* Returns zero if it is not recognised as a share, 1 if it is a valid share
* and -1 if it is recognised as a share but invalid. */ * and -1 if it is recognised as a share but invalid. */
static int parse_share(ckpool_t *ckp, gdata_t *gdata, proxy_instance_t *proxi, const char *buf) static int parse_share(gdata_t *gdata, proxy_instance_t *proxi, const char *buf)
{ {
json_t *val = NULL, *idval; json_t *val = NULL, *idval;
bool result = false; bool result = false;
@ -1533,14 +1533,12 @@ static int parse_share(ckpool_t *ckp, gdata_t *gdata, proxy_instance_t *proxi, c
proxi->id, proxi->subid, buf); proxi->id, proxi->subid, buf);
/* We don't know what diff these shares are so assume the /* We don't know what diff these shares are so assume the
* current proxy diff. */ * current proxy diff. */
if (!ckp->redirector) account_shares(proxi, proxi->diff, result);
account_shares(proxi, proxi->diff, result);
ret = -1; ret = -1;
goto out; goto out;
} }
ret = 1; ret = 1;
if (!ckp->redirector) account_shares(proxi, share->diff, result);
account_shares(proxi, share->diff, result);
LOGINFO("Proxy %d:%d share result %s from client %d", proxi->id, proxi->subid, LOGINFO("Proxy %d:%d share result %s from client %d", proxi->id, proxi->subid,
buf, share->client_id); buf, share->client_id);
free(share); free(share);
@ -1714,36 +1712,11 @@ static void *proxy_send(void *arg)
return NULL; return NULL;
} }
static void parse_redirector_share(ckpool_t *ckp, const char *msg) static void passthrough_send(ckpool_t __maybe_unused *ckp, pass_msg_t *pm)
{
int64_t client_id;
json_t *val;
val = json_loads(msg, 0, NULL);
if (unlikely(!val)) {
LOGWARNING("Invalid json message in parse_redirector_share: %s", msg);
return;
}
/* Extract the client id from the json message */
client_id = json_integer_value(json_object_get(val, "client_id"));
/* Make sure this is a passthrough client value! */
if (unlikely(client_id < 0xffffffffll)) {
LOGERR("parse_redirector_share got invalid client id %"PRId64, client_id);
goto out;
}
/* Diff is irrelevant here as we don't keep track of it so use 0 */
add_share(ckp->data, client_id, 0);
out:
json_decref(val);
}
static void passthrough_send(ckpool_t *ckp, pass_msg_t *pm)
{ {
int len, sent; int len, sent;
LOGDEBUG("Sending upstream json msg: %s", pm->msg); LOGDEBUG("Sending upstream json msg: %s", pm->msg);
if (ckp->redirector && strstr(pm->msg, "mining.submit"))
parse_redirector_share(ckp, pm->msg);
len = strlen(pm->msg); len = strlen(pm->msg);
sent = write_socket(pm->cs->fd, pm->msg, len); sent = write_socket(pm->cs->fd, pm->msg, len);
if (sent != len) { if (sent != len) {
@ -1909,34 +1882,6 @@ static void reconnect_proxy(proxy_instance_t *proxi)
create_pthread(&pth, proxy_reconnect, proxi); create_pthread(&pth, proxy_reconnect, proxi);
} }
static void redirect_client(ckpool_t *ckp, const char *buf)
{
json_t *json_msg, *val;
int64_t client_id;
char *msg;
json_msg = json_loads(buf, 0, NULL);
if (unlikely(!json_msg)) {
LOGWARNING("Invalid json message in redirect_client: %s", buf);
return;
}
/* Extract the client id from the json message */
client_id = json_integer_value(json_object_get(json_msg, "client_id"));
/* Make sure this is a passthrough client value! */
if (unlikely(client_id < 0xffffffffll)) {
LOGERR("redirect_client got invalid client id %"PRId64, client_id);
goto out;
}
JSON_CPACK(val, "{sIsosss[ssi]}", "id", "client_id", client_id, json_null(),
"method", "client.reconnect", "params", ckp->redirecturl[0], ckp->redirectport[0], 0);
msg = json_dumps(val, JSON_NO_UTF8 | JSON_PRESERVE_ORDER);
json_decref(val);
send_proc(ckp->connector, msg);
free(msg);
out:
json_decref(json_msg);
}
/* 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)
@ -1981,12 +1926,6 @@ static void *passthrough_recv(void *arg)
* process. Possibly parse parameters sent by upstream pool * process. Possibly parse parameters sent by upstream pool
* here */ * here */
send_proc(ckp->connector, cs->buf); send_proc(ckp->connector, cs->buf);
/* If we're a redirecting passthrough, look for a share
* responses here and redirect on a valid share. */
if (ckp->redirector && parse_share(ckp, ckp->data, proxi, cs->buf) > 0)
redirect_client(ckp, cs->buf);
} }
return NULL; return NULL;
} }
@ -2105,7 +2044,7 @@ static void *proxy_recv(void *arg)
if (parse_method(ckp, subproxy, cs->buf)) if (parse_method(ckp, subproxy, cs->buf))
continue; continue;
/* If it's not a method it should be a share result */ /* If it's not a method it should be a share result */
if (!parse_share(ckp, gdata, subproxy, cs->buf)) { if (!parse_share(gdata, subproxy, cs->buf)) {
LOGNOTICE("Proxy %d:%d unhandled stratum message: %s", LOGNOTICE("Proxy %d:%d unhandled stratum message: %s",
subproxy->id, subproxy->subid, cs->buf); subproxy->id, subproxy->subid, cs->buf);
} }
@ -2192,7 +2131,7 @@ static void *userproxy_recv(void *arg)
if (parse_method(ckp, proxy, cs->buf)) if (parse_method(ckp, proxy, cs->buf))
continue; continue;
/* If it's not a method it should be a share result */ /* If it's not a method it should be a share result */
if (!parse_share(ckp, gdata, proxy, cs->buf)) { if (!parse_share(gdata, proxy, cs->buf)) {
LOGNOTICE("Proxy %d:%d unhandled stratum message: %s", LOGNOTICE("Proxy %d:%d unhandled stratum message: %s",
proxy->id, proxy->subid, cs->buf); proxy->id, proxy->subid, cs->buf);
} }

Loading…
Cancel
Save