|
|
@ -1219,6 +1219,13 @@ bool extract_sockaddr(char *url, char **sockaddr_url, char **sockaddr_port) |
|
|
|
|
|
|
|
|
|
|
|
if (url_len < 1) |
|
|
|
if (url_len < 1) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (url_len >= sizeof(url_address)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
applog(LOG_WARNING, "%s: Truncating overflowed address '%.*s'", |
|
|
|
|
|
|
|
__func__, url_len, url_begin); |
|
|
|
|
|
|
|
url_len = sizeof(url_address) - 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sprintf(url_address, "%.*s", url_len, url_begin); |
|
|
|
sprintf(url_address, "%.*s", url_len, url_begin); |
|
|
|
|
|
|
|
|
|
|
@ -1593,17 +1600,23 @@ static bool parse_notify(struct pool *pool, json_t *val) |
|
|
|
pool->swork.nbit, |
|
|
|
pool->swork.nbit, |
|
|
|
"00000000", /* nonce */ |
|
|
|
"00000000", /* nonce */ |
|
|
|
workpadding); |
|
|
|
workpadding); |
|
|
|
if (unlikely(!hex2bin(pool->header_bin, header, 128))) |
|
|
|
if (unlikely(!hex2bin(pool->header_bin, header, 128))) { |
|
|
|
quit(1, "Failed to convert header to header_bin in parse_notify"); |
|
|
|
applog(LOG_WARNING, "%s: Failed to convert header to header_bin, got %s", __func__, header); |
|
|
|
|
|
|
|
pool_failed(pool); |
|
|
|
|
|
|
|
// TODO: memory leaks? goto out, clean up there?
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cb1 = (unsigned char *)calloc(cb1_len, 1); |
|
|
|
cb1 = (unsigned char *)calloc(cb1_len, 1); |
|
|
|
if (unlikely(!cb1)) |
|
|
|
if (unlikely(!cb1)) |
|
|
|
quithere(1, "Failed to calloc cb1 in parse_notify"); |
|
|
|
quithere(1, "Failed to calloc cb1 in parse_notify"); |
|
|
|
hex2bin(cb1, coinbase1, cb1_len); |
|
|
|
hex2bin(cb1, coinbase1, cb1_len); |
|
|
|
|
|
|
|
|
|
|
|
cb2 = (unsigned char *)calloc(cb2_len, 1); |
|
|
|
cb2 = (unsigned char *)calloc(cb2_len, 1); |
|
|
|
if (unlikely(!cb2)) |
|
|
|
if (unlikely(!cb2)) |
|
|
|
quithere(1, "Failed to calloc cb2 in parse_notify"); |
|
|
|
quithere(1, "Failed to calloc cb2 in parse_notify"); |
|
|
|
hex2bin(cb2, coinbase2, cb2_len); |
|
|
|
hex2bin(cb2, coinbase2, cb2_len); |
|
|
|
|
|
|
|
|
|
|
|
free(pool->coinbase); |
|
|
|
free(pool->coinbase); |
|
|
|
align_len(&alloc_len); |
|
|
|
align_len(&alloc_len); |
|
|
|
pool->coinbase = (unsigned char *)calloc(alloc_len, 1); |
|
|
|
pool->coinbase = (unsigned char *)calloc(alloc_len, 1); |
|
|
@ -1611,6 +1624,7 @@ static bool parse_notify(struct pool *pool, json_t *val) |
|
|
|
quit(1, "Failed to calloc pool coinbase in parse_notify"); |
|
|
|
quit(1, "Failed to calloc pool coinbase in parse_notify"); |
|
|
|
memcpy(pool->coinbase, cb1, cb1_len); |
|
|
|
memcpy(pool->coinbase, cb1, cb1_len); |
|
|
|
memcpy(pool->coinbase + cb1_len, pool->nonce1bin, pool->n1_len); |
|
|
|
memcpy(pool->coinbase + cb1_len, pool->nonce1bin, pool->n1_len); |
|
|
|
|
|
|
|
// NOTE: gap for nonce2, filled at work generation time
|
|
|
|
memcpy(pool->coinbase + cb1_len + pool->n1_len + pool->n2size, cb2, cb2_len); |
|
|
|
memcpy(pool->coinbase + cb1_len + pool->n1_len + pool->n2size, cb2, cb2_len); |
|
|
|
cg_wunlock(&pool->data_lock); |
|
|
|
cg_wunlock(&pool->data_lock); |
|
|
|
|
|
|
|
|
|
|
@ -1711,15 +1725,14 @@ static void __suspend_stratum(struct pool *pool) |
|
|
|
|
|
|
|
|
|
|
|
static bool parse_reconnect(struct pool *pool, json_t *val) |
|
|
|
static bool parse_reconnect(struct pool *pool, json_t *val) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char *sockaddr_url, *stratum_port, *tmp; |
|
|
|
|
|
|
|
char *url, *port, address[256]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (opt_disable_client_reconnect) { |
|
|
|
if (opt_disable_client_reconnect) { |
|
|
|
applog(LOG_WARNING, "Stratum client.reconnect forbidden, aborting."); |
|
|
|
applog(LOG_WARNING, "Stratum client.reconnect received but is disabled, not reconnecting."); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
memset(address, 0, 255); |
|
|
|
char *url, *port, address[256]; |
|
|
|
|
|
|
|
char *sockaddr_url, *stratum_port, *tmp; /* Tempvars. */ |
|
|
|
|
|
|
|
|
|
|
|
url = (char *)json_string_value(json_array_get(val, 0)); |
|
|
|
url = (char *)json_string_value(json_array_get(val, 0)); |
|
|
|
if (!url) |
|
|
|
if (!url) |
|
|
|
url = pool->sockaddr_url; |
|
|
|
url = pool->sockaddr_url; |
|
|
@ -1728,8 +1741,7 @@ static bool parse_reconnect(struct pool *pool, json_t *val) |
|
|
|
if (!port) |
|
|
|
if (!port) |
|
|
|
port = pool->stratum_port; |
|
|
|
port = pool->stratum_port; |
|
|
|
|
|
|
|
|
|
|
|
sprintf(address, "%s:%s", url, port); |
|
|
|
snprintf(address, sizeof(address), "%s:%s", url, port); |
|
|
|
|
|
|
|
|
|
|
|
if (!extract_sockaddr(address, &sockaddr_url, &stratum_port)) |
|
|
|
if (!extract_sockaddr(address, &sockaddr_url, &stratum_port)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
@ -2505,7 +2517,8 @@ resend: |
|
|
|
goto out; |
|
|
|
goto out; |
|
|
|
} |
|
|
|
} |
|
|
|
n2size = json_integer_value(json_array_get(res_val, 2)); |
|
|
|
n2size = json_integer_value(json_array_get(res_val, 2)); |
|
|
|
if (!n2size) { |
|
|
|
if (n2size < 1) |
|
|
|
|
|
|
|
{ |
|
|
|
applog(LOG_INFO, "Failed to get n2size in initiate_stratum"); |
|
|
|
applog(LOG_INFO, "Failed to get n2size in initiate_stratum"); |
|
|
|
free(sessionid); |
|
|
|
free(sessionid); |
|
|
|
free(nonce1); |
|
|
|
free(nonce1); |
|
|
|