|
|
|
@ -1247,7 +1247,7 @@ static bool parse_reconnect(struct pool *pool, json_t *val)
@@ -1247,7 +1247,7 @@ static bool parse_reconnect(struct pool *pool, json_t *val)
|
|
|
|
|
|
|
|
|
|
applog(LOG_NOTICE, "Reconnect requested from pool %d to %s", pool->pool_no, address); |
|
|
|
|
|
|
|
|
|
if (!initiate_stratum(pool) || !auth_stratum(pool)) |
|
|
|
|
if (!restart_stratum(pool)) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
@ -1391,15 +1391,12 @@ out:
@@ -1391,15 +1391,12 @@ out:
|
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool initiate_stratum(struct pool *pool) |
|
|
|
|
static bool setup_stratum_curl(struct pool *pool) |
|
|
|
|
{ |
|
|
|
|
json_t *val = NULL, *res_val, *err_val; |
|
|
|
|
char curl_err_str[CURL_ERROR_SIZE]; |
|
|
|
|
char s[RBUFSIZE], *sret = NULL; |
|
|
|
|
CURL *curl = NULL; |
|
|
|
|
double byte_count; |
|
|
|
|
json_error_t err; |
|
|
|
|
bool ret = false; |
|
|
|
|
char s[RBUFSIZE]; |
|
|
|
|
|
|
|
|
|
mutex_lock(&pool->stratum_lock); |
|
|
|
|
pool->stratum_active = false; |
|
|
|
@ -1419,7 +1416,6 @@ bool initiate_stratum(struct pool *pool)
@@ -1419,7 +1416,6 @@ bool initiate_stratum(struct pool *pool)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Create a http url for use with curl */ |
|
|
|
|
memset(s, 0, RBUFSIZE); |
|
|
|
|
sprintf(s, "http://%s:%s", pool->sockaddr_url, pool->stratum_port); |
|
|
|
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1); |
|
|
|
@ -1439,7 +1435,7 @@ bool initiate_stratum(struct pool *pool)
@@ -1439,7 +1435,7 @@ bool initiate_stratum(struct pool *pool)
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1); |
|
|
|
|
if (curl_easy_perform(curl)) { |
|
|
|
|
applog(LOG_INFO, "Stratum connect failed to pool %d: %s", pool->pool_no, curl_err_str); |
|
|
|
|
goto out; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, (long *)&pool->sock); |
|
|
|
|
keep_alive(curl, pool->sock); |
|
|
|
@ -1451,6 +1447,19 @@ bool initiate_stratum(struct pool *pool)
@@ -1451,6 +1447,19 @@ bool initiate_stratum(struct pool *pool)
|
|
|
|
|
if (curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &byte_count) == CURLE_OK) |
|
|
|
|
pool->cgminer_pool_stats.bytes_received += byte_count; |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool initiate_stratum(struct pool *pool) |
|
|
|
|
{ |
|
|
|
|
json_t *val = NULL, *res_val, *err_val; |
|
|
|
|
char s[RBUFSIZE], *sret = NULL; |
|
|
|
|
json_error_t err; |
|
|
|
|
bool ret = false; |
|
|
|
|
|
|
|
|
|
if (!setup_stratum_curl(pool)) |
|
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", swork_id++); |
|
|
|
|
|
|
|
|
|
if (!__stratum_send(pool, s, strlen(s))) { |
|
|
|
@ -1504,6 +1513,11 @@ bool initiate_stratum(struct pool *pool)
@@ -1504,6 +1513,11 @@ bool initiate_stratum(struct pool *pool)
|
|
|
|
|
applog(LOG_INFO, "Failed to get n2size in initiate_stratum"); |
|
|
|
|
goto out; |
|
|
|
|
} |
|
|
|
|
pool->sessionid = json_array_string(res_val, 3); |
|
|
|
|
if (pool->sessionid) |
|
|
|
|
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"); |
|
|
|
|
|
|
|
|
|
ret = true; |
|
|
|
|
out: |
|
|
|
@ -1525,6 +1539,110 @@ out:
@@ -1525,6 +1539,110 @@ out:
|
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void reset_sessionid(struct pool *pool) |
|
|
|
|
{ |
|
|
|
|
mutex_lock(&pool->pool_lock); |
|
|
|
|
free(pool->sessionid); |
|
|
|
|
pool->sessionid = NULL; |
|
|
|
|
mutex_unlock(&pool->pool_lock); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Placeholder for real resume function in the future */ |
|
|
|
|
static bool resume_stratum(struct pool *pool) |
|
|
|
|
{ |
|
|
|
|
json_t *val = NULL, *err_val, *res_val; |
|
|
|
|
char s[RBUFSIZE], *sret = NULL; |
|
|
|
|
json_error_t err; |
|
|
|
|
bool ret = false; |
|
|
|
|
|
|
|
|
|
if (!setup_stratum_curl(pool)) |
|
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
mutex_lock(&pool->pool_lock); |
|
|
|
|
sprintf(s, "{\"id\": %d, \"method\": \"mining.resume\", \"params\": [\"%s\"]}", swork_id++, pool->sessionid); |
|
|
|
|
mutex_unlock(&pool->pool_lock); |
|
|
|
|
|
|
|
|
|
if (!__stratum_send(pool, s, strlen(s))) { |
|
|
|
|
applog(LOG_DEBUG, "Failed to send s in resume_stratum"); |
|
|
|
|
goto out; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!socket_full(pool, true)) { |
|
|
|
|
applog(LOG_DEBUG, "Timed out waiting for response in resume_stratum"); |
|
|
|
|
goto out; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sret = recv_line(pool); |
|
|
|
|
if (!sret) |
|
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
val = JSON_LOADS(sret, &err); |
|
|
|
|
free(sret); |
|
|
|
|
if (!val) { |
|
|
|
|
applog(LOG_INFO, "JSON decode failed(%d): %s", err.line, err.text); |
|
|
|
|
goto out; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
res_val = json_object_get(val, "result"); |
|
|
|
|
err_val = json_object_get(val, "error"); |
|
|
|
|
|
|
|
|
|
/* If there is an error, assume resume support is not there or broken */ |
|
|
|
|
if (!res_val || json_is_null(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_INFO, "JSON-RPC decode failed: %s", ss); |
|
|
|
|
|
|
|
|
|
free(ss); |
|
|
|
|
|
|
|
|
|
reset_sessionid(pool); |
|
|
|
|
goto out; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (json_is_true(res_val)) { |
|
|
|
|
applog(LOG_NOTICE, "Resumed stratum connection to pool %d", pool->pool_no); |
|
|
|
|
pool->stratum_active = true; |
|
|
|
|
ret = true; |
|
|
|
|
} else { |
|
|
|
|
applog(LOG_NOTICE, "Unable to resume old stratum connection to pool %d", pool->pool_no); |
|
|
|
|
reset_sessionid(pool); |
|
|
|
|
clear_stratum_shares(pool); |
|
|
|
|
json_decref(val); |
|
|
|
|
|
|
|
|
|
return initiate_stratum(pool); |
|
|
|
|
} |
|
|
|
|
out: |
|
|
|
|
if (val) |
|
|
|
|
json_decref(val); |
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool restart_stratum(struct pool *pool) |
|
|
|
|
{ |
|
|
|
|
bool resume; |
|
|
|
|
|
|
|
|
|
mutex_lock(&pool->pool_lock); |
|
|
|
|
resume = pool->sessionid != NULL; |
|
|
|
|
mutex_unlock(&pool->pool_lock); |
|
|
|
|
|
|
|
|
|
if (resume) { |
|
|
|
|
if (!resume_stratum(pool)) |
|
|
|
|
return false; |
|
|
|
|
} else { |
|
|
|
|
if (!initiate_stratum(pool)) |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (!auth_stratum(pool)) |
|
|
|
|
return false; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void suspend_stratum(struct pool *pool) |
|
|
|
|
{ |
|
|
|
|
applog(LOG_INFO, "Closing socket for stratum pool %d", pool->pool_no); |
|
|
|
|