|
|
@ -489,7 +489,7 @@ static void parse_client_msg(cdata_t *cdata, client_instance_t *client) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int buflen, ret, slen = 0, blen = 0; |
|
|
|
int buflen, ret, slen = 0, blen = 0; |
|
|
|
ckpool_t *ckp = cdata->ckp; |
|
|
|
ckpool_t *ckp = cdata->ckp; |
|
|
|
char *msg, *eol, *bkey; |
|
|
|
char *eol, *bkey = NULL; |
|
|
|
json_t *val; |
|
|
|
json_t *val; |
|
|
|
|
|
|
|
|
|
|
|
retry: |
|
|
|
retry: |
|
|
@ -539,26 +539,18 @@ reparse: |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
msg = alloca(round_up_page(buflen + 1)); |
|
|
|
if (!(val = json_loads(client->buf, JSON_DISABLE_EOF_CHECK, NULL))) { |
|
|
|
memcpy(msg, client->buf, buflen); |
|
|
|
|
|
|
|
msg[buflen] = '\0'; |
|
|
|
|
|
|
|
client->bufofs -= buflen; |
|
|
|
|
|
|
|
memmove(client->buf, client->buf + buflen, client->bufofs); |
|
|
|
|
|
|
|
client->buf[client->bufofs] = '\0'; |
|
|
|
|
|
|
|
if (!(val = json_loads(msg, JSON_DISABLE_EOF_CHECK, NULL))) { |
|
|
|
|
|
|
|
char *buf = strdup("Invalid JSON, disconnecting\n"); |
|
|
|
char *buf = strdup("Invalid JSON, disconnecting\n"); |
|
|
|
|
|
|
|
|
|
|
|
LOGINFO("Client id %"PRId64" sent invalid json message %s", client->id, msg); |
|
|
|
LOGINFO("Client id %"PRId64" sent invalid json message %s", client->id, client->buf); |
|
|
|
send_client_msg(cdata, client->id, buf); |
|
|
|
send_client_msg(cdata, client->id, buf); |
|
|
|
invalidate_client(ckp, cdata, client); |
|
|
|
invalidate_client(ckp, cdata, client); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
char *s; |
|
|
|
char *s; |
|
|
|
|
|
|
|
|
|
|
|
if (unlikely(blen)) { |
|
|
|
if (unlikely(blen)) |
|
|
|
bkey = msg + slen + 1; |
|
|
|
|
|
|
|
json_append_bkeys(val, bkey, blen); |
|
|
|
json_append_bkeys(val, bkey, blen); |
|
|
|
} |
|
|
|
|
|
|
|
if (client->passthrough) { |
|
|
|
if (client->passthrough) { |
|
|
|
int64_t passthrough_id; |
|
|
|
int64_t passthrough_id; |
|
|
|
|
|
|
|
|
|
|
@ -566,7 +558,7 @@ reparse: |
|
|
|
passthrough_id = (client->id << 32) | passthrough_id; |
|
|
|
passthrough_id = (client->id << 32) | passthrough_id; |
|
|
|
json_object_set_new_nocheck(val, "client_id", json_integer(passthrough_id)); |
|
|
|
json_object_set_new_nocheck(val, "client_id", json_integer(passthrough_id)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (ckp->redirector && !client->redirected && strstr(msg, "mining.submit")) |
|
|
|
if (ckp->redirector && !client->redirected && strstr(client->buf, "mining.submit")) |
|
|
|
parse_redirector_share(client, val); |
|
|
|
parse_redirector_share(client, val); |
|
|
|
json_object_set_new_nocheck(val, "client_id", json_integer(client->id)); |
|
|
|
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, "address", json_string(client->address_name)); |
|
|
@ -587,6 +579,9 @@ reparse: |
|
|
|
free(s); |
|
|
|
free(s); |
|
|
|
json_decref(val); |
|
|
|
json_decref(val); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
client->bufofs -= buflen; |
|
|
|
|
|
|
|
memmove(client->buf, client->buf + buflen, client->bufofs); |
|
|
|
|
|
|
|
client->buf[client->bufofs] = '\0'; |
|
|
|
|
|
|
|
|
|
|
|
if (client->bufofs) |
|
|
|
if (client->bufofs) |
|
|
|
goto reparse; |
|
|
|
goto reparse; |
|
|
|