|
|
@ -1363,38 +1363,46 @@ bool auth_stratum(struct pool *pool) |
|
|
|
json_error_t err; |
|
|
|
json_error_t err; |
|
|
|
bool ret = false; |
|
|
|
bool ret = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pool->stratum_notify = false; |
|
|
|
|
|
|
|
|
|
|
|
sprintf(s, "{\"id\": %d, \"method\": \"mining.authorize\", \"params\": [\"%s\", \"%s\"]}", |
|
|
|
sprintf(s, "{\"id\": %d, \"method\": \"mining.authorize\", \"params\": [\"%s\", \"%s\"]}", |
|
|
|
swork_id++, pool->rpc_user, pool->rpc_pass); |
|
|
|
swork_id++, pool->rpc_user, pool->rpc_pass); |
|
|
|
|
|
|
|
|
|
|
|
if (!stratum_send(pool, s, strlen(s))) |
|
|
|
if (!stratum_send(pool, s, strlen(s))) |
|
|
|
goto out; |
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
|
|
/* Parse all data in the queue and anything left should be auth */ |
|
|
|
/* Parse all data in the queue and break out should we run out of data
|
|
|
|
|
|
|
|
* or we have successfully parsed a notify message. */ |
|
|
|
while (42) { |
|
|
|
while (42) { |
|
|
|
sret = recv_line(pool); |
|
|
|
sret = recv_line(pool); |
|
|
|
if (!sret) |
|
|
|
if (!sret) |
|
|
|
goto out; |
|
|
|
goto out; |
|
|
|
if (parse_method(pool, sret)) |
|
|
|
if (parse_method(pool, sret)) { |
|
|
|
free(sret); |
|
|
|
free(sret); |
|
|
|
else |
|
|
|
if (pool->stratum_notify) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} else |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val = JSON_LOADS(sret, &err); |
|
|
|
if (!pool->stratum_notify) { |
|
|
|
free(sret); |
|
|
|
val = JSON_LOADS(sret, &err); |
|
|
|
res_val = json_object_get(val, "result"); |
|
|
|
free(sret); |
|
|
|
err_val = json_object_get(val, "error"); |
|
|
|
res_val = json_object_get(val, "result"); |
|
|
|
|
|
|
|
err_val = json_object_get(val, "error"); |
|
|
|
if (!res_val || json_is_false(res_val) || (err_val && !json_is_null(err_val))) { |
|
|
|
|
|
|
|
char *ss; |
|
|
|
if (!res_val || json_is_false(res_val) || (err_val && !json_is_null(err_val))) { |
|
|
|
|
|
|
|
char *ss; |
|
|
|
if (err_val) |
|
|
|
|
|
|
|
ss = json_dumps(err_val, JSON_INDENT(3)); |
|
|
|
if (err_val) |
|
|
|
else |
|
|
|
ss = json_dumps(err_val, JSON_INDENT(3)); |
|
|
|
ss = strdup("(unknown reason)"); |
|
|
|
else |
|
|
|
applog(LOG_WARNING, "JSON stratum auth failed: %s", ss); |
|
|
|
ss = strdup("(unknown reason)"); |
|
|
|
free(ss); |
|
|
|
applog(LOG_WARNING, "JSON stratum auth failed: %s", ss); |
|
|
|
|
|
|
|
free(ss); |
|
|
|
|
|
|
|
goto out; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
applog(LOG_WARNING, "Failed to auth stratum"); |
|
|
|
goto out; |
|
|
|
goto out; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|