|
|
|
@ -1426,14 +1426,16 @@ static bool setup_stratum_curl(struct pool *pool)
@@ -1426,14 +1426,16 @@ static bool setup_stratum_curl(struct pool *pool)
|
|
|
|
|
|
|
|
|
|
bool initiate_stratum(struct pool *pool) |
|
|
|
|
{ |
|
|
|
|
char s[RBUFSIZE], *sret = NULL, *nonce1, *sessionid; |
|
|
|
|
json_t *val = NULL, *res_val, *err_val; |
|
|
|
|
char s[RBUFSIZE], *sret = NULL; |
|
|
|
|
bool ret = false, recvd = false; |
|
|
|
|
json_error_t err; |
|
|
|
|
bool ret = false; |
|
|
|
|
int n2size; |
|
|
|
|
|
|
|
|
|
if (!setup_stratum_curl(pool)) |
|
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
resend: |
|
|
|
|
if (pool->sessionid) |
|
|
|
|
sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"%s\"]}", swork_id++, pool->sessionid); |
|
|
|
|
else |
|
|
|
@ -1453,6 +1455,8 @@ bool initiate_stratum(struct pool *pool)
@@ -1453,6 +1455,8 @@ bool initiate_stratum(struct pool *pool)
|
|
|
|
|
if (!sret) |
|
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
recvd = true; |
|
|
|
|
|
|
|
|
|
val = JSON_LOADS(sret, &err); |
|
|
|
|
free(sret); |
|
|
|
|
if (!val) { |
|
|
|
@ -1479,22 +1483,33 @@ bool initiate_stratum(struct pool *pool)
@@ -1479,22 +1483,33 @@ bool initiate_stratum(struct pool *pool)
|
|
|
|
|
goto out; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pool->nonce1 = json_array_string(res_val, 1); |
|
|
|
|
if (!pool->nonce1) { |
|
|
|
|
sessionid = json_array_string(json_array_get(res_val, 0), 1); |
|
|
|
|
if (!sessionid) { |
|
|
|
|
applog(LOG_INFO, "Failed to get sessionid in initiate_stratum"); |
|
|
|
|
goto out; |
|
|
|
|
} |
|
|
|
|
nonce1 = json_array_string(res_val, 1); |
|
|
|
|
if (!nonce1) { |
|
|
|
|
applog(LOG_INFO, "Failed to get nonce1 in initiate_stratum"); |
|
|
|
|
free(sessionid); |
|
|
|
|
goto out; |
|
|
|
|
} |
|
|
|
|
pool->n1_len = strlen(pool->nonce1) / 2; |
|
|
|
|
pool->n2size = json_integer_value(json_array_get(res_val, 2)); |
|
|
|
|
if (!pool->n2size) { |
|
|
|
|
n2size = json_integer_value(json_array_get(res_val, 2)); |
|
|
|
|
if (!n2size) { |
|
|
|
|
applog(LOG_INFO, "Failed to get n2size in initiate_stratum"); |
|
|
|
|
free(sessionid); |
|
|
|
|
free(nonce1); |
|
|
|
|
goto out; |
|
|
|
|
} |
|
|
|
|
//pool->sessionid = json_array_string(res_val, 3);
|
|
|
|
|
if (pool->sessionid) |
|
|
|
|
|
|
|
|
|
mutex_lock(&pool->pool_lock); |
|
|
|
|
pool->sessionid = sessionid; |
|
|
|
|
pool->nonce1 = nonce1; |
|
|
|
|
pool->n1_len = strlen(nonce1) / 2; |
|
|
|
|
pool->n2size = n2size; |
|
|
|
|
mutex_unlock(&pool->pool_lock); |
|
|
|
|
|
|
|
|
|
applog(LOG_DEBUG, "Pool %d stratum session id: %s", pool->pool_no, pool->sessionid); |
|
|
|
|
else |
|
|
|
|
applog(LOG_DEBUG, "Pool %d stratum session id does not exist", pool->pool_no); |
|
|
|
|
|
|
|
|
|
ret = true; |
|
|
|
|
out: |
|
|
|
@ -1510,8 +1525,21 @@ out:
@@ -1510,8 +1525,21 @@ out:
|
|
|
|
|
applog(LOG_DEBUG, "Pool %d confirmed mining.subscribe with extranonce1 %s extran2size %d", |
|
|
|
|
pool->pool_no, pool->nonce1, pool->n2size); |
|
|
|
|
} |
|
|
|
|
} else |
|
|
|
|
} else { |
|
|
|
|
if (recvd && pool->sessionid) { |
|
|
|
|
/* Reset the sessionid used for stratum resuming in case the pool
|
|
|
|
|
* does not support it, or does not know how to respond to the |
|
|
|
|
* presence of the sessionid parameter. */ |
|
|
|
|
mutex_lock(&pool->pool_lock); |
|
|
|
|
free(pool->sessionid); |
|
|
|
|
free(pool->nonce1); |
|
|
|
|
pool->sessionid = pool->nonce1 = NULL; |
|
|
|
|
mutex_unlock(&pool->pool_lock); |
|
|
|
|
applog(LOG_DEBUG, "Failed to resume stratum, trying afresh"); |
|
|
|
|
goto resend; |
|
|
|
|
} |
|
|
|
|
applog(LOG_DEBUG, "Initiate stratum failed"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|