From ac9a4378d1e32ac51d054185ac6746fab771ff2c Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 28 Sep 2012 10:31:45 +1000 Subject: [PATCH] Complete authorisation in stratum. --- util.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/util.c b/util.c index 211cc1c1..54f795e9 100644 --- a/util.c +++ b/util.c @@ -1105,7 +1105,7 @@ out: bool auth_stratum(struct pool *pool) { json_t *val = NULL, *res_val, *err_val; - char *s, *buf, *sret = NULL; + char *s, *sret = NULL; json_error_t err; bool ret = false; @@ -1113,6 +1113,7 @@ bool auth_stratum(struct pool *pool) sprintf(s, "{\"id\": %d, \"method\": \"mining.authorize\", \"params\": [\"%s\", \"%s\"]}", pool->swork.id++, pool->rpc_user, pool->rpc_pass); + /* Parse all data prior sending auth request */ while (sock_full(pool->sock, false)) { sret = recv_line(pool->sock); parse_stratum(pool, sret); @@ -1122,10 +1123,34 @@ bool auth_stratum(struct pool *pool) if (!sock_send(pool->sock, s, strlen(s))) goto out; + sret = recv_line(pool->sock); + if (!sret) + goto out; + val = JSON_LOADS(sret, &err); + free(sret); + 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 (err_val) + ss = json_dumps(err_val, JSON_INDENT(3)); + else + ss = strdup("(unknown reason)"); + applog(LOG_WARNING, "JSON stratum auth failed: %s", ss); + free(ss); + + goto out; + } + ret = true; + applog(LOG_INFO, "Stratum authorisation success for pool %d", pool->pool_no); out: if (val) json_decref(val); + pool->stratum_auth = ret; + return ret; }