|
|
@ -177,8 +177,7 @@ static bool server_alive(ckpool_t *ckp, server_instance_t *si, bool pinging) |
|
|
|
out: |
|
|
|
out: |
|
|
|
if (!ret) { |
|
|
|
if (!ret) { |
|
|
|
/* Close and invalidate the file handle */ |
|
|
|
/* Close and invalidate the file handle */ |
|
|
|
close(cs->fd); |
|
|
|
Close(cs->fd); |
|
|
|
cs->fd = -1; |
|
|
|
|
|
|
|
} else |
|
|
|
} else |
|
|
|
keep_sockalive(cs->fd); |
|
|
|
keep_sockalive(cs->fd); |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
@ -225,8 +224,7 @@ static void kill_server(server_instance_t *si) |
|
|
|
|
|
|
|
|
|
|
|
LOGNOTICE("Killing server"); |
|
|
|
LOGNOTICE("Killing server"); |
|
|
|
cs = &si->cs; |
|
|
|
cs = &si->cs; |
|
|
|
close(cs->fd); |
|
|
|
Close(cs->fd); |
|
|
|
cs->fd = -1; |
|
|
|
|
|
|
|
dealloc(cs->url); |
|
|
|
dealloc(cs->url); |
|
|
|
dealloc(cs->port); |
|
|
|
dealloc(cs->port); |
|
|
|
dealloc(cs->auth); |
|
|
|
dealloc(cs->auth); |
|
|
@ -290,7 +288,7 @@ retry: |
|
|
|
buf = recv_unix_msg(sockd); |
|
|
|
buf = recv_unix_msg(sockd); |
|
|
|
if (!buf) { |
|
|
|
if (!buf) { |
|
|
|
LOGWARNING("Failed to get message in gen_loop"); |
|
|
|
LOGWARNING("Failed to get message in gen_loop"); |
|
|
|
close(sockd); |
|
|
|
Close(sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
LOGDEBUG("Generator received request: %s", buf); |
|
|
|
LOGDEBUG("Generator received request: %s", buf); |
|
|
@ -365,7 +363,7 @@ retry: |
|
|
|
LOGDEBUG("Generator received ping request"); |
|
|
|
LOGDEBUG("Generator received ping request"); |
|
|
|
send_unix_msg(sockd, "pong"); |
|
|
|
send_unix_msg(sockd, "pong"); |
|
|
|
} |
|
|
|
} |
|
|
|
close(sockd); |
|
|
|
Close(sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
|
|
|
|
|
|
|
|
out: |
|
|
|
out: |
|
|
@ -627,10 +625,8 @@ retry: |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
|
|
|
|
|
|
|
|
out: |
|
|
|
out: |
|
|
|
if (!ret) { |
|
|
|
if (!ret) |
|
|
|
close(cs->fd); |
|
|
|
Close(cs->fd); |
|
|
|
cs->fd = -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -670,7 +666,7 @@ out: |
|
|
|
if (val) |
|
|
|
if (val) |
|
|
|
json_decref(val); |
|
|
|
json_decref(val); |
|
|
|
if (!ret) |
|
|
|
if (!ret) |
|
|
|
close(cs->fd); |
|
|
|
Close(cs->fd); |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -934,7 +930,7 @@ static bool auth_stratum(connsock_t *cs, proxy_instance_t *proxi) |
|
|
|
json_decref(req); |
|
|
|
json_decref(req); |
|
|
|
if (!ret) { |
|
|
|
if (!ret) { |
|
|
|
LOGWARNING("Failed to send message in auth_stratum"); |
|
|
|
LOGWARNING("Failed to send message in auth_stratum"); |
|
|
|
close(cs->fd); |
|
|
|
Close(cs->fd); |
|
|
|
goto out; |
|
|
|
goto out; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -979,7 +975,7 @@ out: |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void send_subscribe(proxy_instance_t *proxi, int sockd) |
|
|
|
static void send_subscribe(proxy_instance_t *proxi, int *sockd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
json_t *json_msg; |
|
|
|
json_t *json_msg; |
|
|
|
char *msg; |
|
|
|
char *msg; |
|
|
@ -988,12 +984,12 @@ static void send_subscribe(proxy_instance_t *proxi, int sockd) |
|
|
|
"nonce2len", proxi->nonce2len); |
|
|
|
"nonce2len", proxi->nonce2len); |
|
|
|
msg = json_dumps(json_msg, JSON_NO_UTF8); |
|
|
|
msg = json_dumps(json_msg, JSON_NO_UTF8); |
|
|
|
json_decref(json_msg); |
|
|
|
json_decref(json_msg); |
|
|
|
send_unix_msg(sockd, msg); |
|
|
|
send_unix_msg(*sockd, msg); |
|
|
|
free(msg); |
|
|
|
free(msg); |
|
|
|
close(sockd); |
|
|
|
_Close(sockd); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void send_notify(proxy_instance_t *proxi, int sockd) |
|
|
|
static void send_notify(proxy_instance_t *proxi, int *sockd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
json_t *json_msg, *merkle_arr; |
|
|
|
json_t *json_msg, *merkle_arr; |
|
|
|
notify_instance_t *ni; |
|
|
|
notify_instance_t *ni; |
|
|
@ -1017,12 +1013,12 @@ static void send_notify(proxy_instance_t *proxi, int sockd) |
|
|
|
|
|
|
|
|
|
|
|
msg = json_dumps(json_msg, JSON_NO_UTF8); |
|
|
|
msg = json_dumps(json_msg, JSON_NO_UTF8); |
|
|
|
json_decref(json_msg); |
|
|
|
json_decref(json_msg); |
|
|
|
send_unix_msg(sockd, msg); |
|
|
|
send_unix_msg(*sockd, msg); |
|
|
|
free(msg); |
|
|
|
free(msg); |
|
|
|
close(sockd); |
|
|
|
_Close(sockd); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void send_diff(proxy_instance_t *proxi, int sockd) |
|
|
|
static void send_diff(proxy_instance_t *proxi, int *sockd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
json_t *json_msg; |
|
|
|
json_t *json_msg; |
|
|
|
char *msg; |
|
|
|
char *msg; |
|
|
@ -1030,9 +1026,9 @@ static void send_diff(proxy_instance_t *proxi, int sockd) |
|
|
|
JSON_CPACK(json_msg, "{sf}", "diff", proxi->diff); |
|
|
|
JSON_CPACK(json_msg, "{sf}", "diff", proxi->diff); |
|
|
|
msg = json_dumps(json_msg, JSON_NO_UTF8); |
|
|
|
msg = json_dumps(json_msg, JSON_NO_UTF8); |
|
|
|
json_decref(json_msg); |
|
|
|
json_decref(json_msg); |
|
|
|
send_unix_msg(sockd, msg); |
|
|
|
send_unix_msg(*sockd, msg); |
|
|
|
free(msg); |
|
|
|
free(msg); |
|
|
|
close(sockd); |
|
|
|
_Close(sockd); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void submit_share(proxy_instance_t *proxi, json_t *val) |
|
|
|
static void submit_share(proxy_instance_t *proxi, json_t *val) |
|
|
@ -1242,8 +1238,7 @@ static void *proxy_send(void *arg) |
|
|
|
free(msg); |
|
|
|
free(msg); |
|
|
|
if (!ret && cs->fd > 0) { |
|
|
|
if (!ret && cs->fd > 0) { |
|
|
|
LOGWARNING("Failed to send msg in proxy_send, dropping to reconnect"); |
|
|
|
LOGWARNING("Failed to send msg in proxy_send, dropping to reconnect"); |
|
|
|
close(cs->fd); |
|
|
|
Close(cs->fd); |
|
|
|
cs->fd = -1; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
@ -1350,8 +1345,7 @@ static bool proxy_alive(ckpool_t *ckp, server_instance_t *si, proxy_instance_t * |
|
|
|
out: |
|
|
|
out: |
|
|
|
if (!ret) { |
|
|
|
if (!ret) { |
|
|
|
/* Close and invalidate the file handle */ |
|
|
|
/* Close and invalidate the file handle */ |
|
|
|
close(cs->fd); |
|
|
|
Close(cs->fd); |
|
|
|
cs->fd = -1; |
|
|
|
|
|
|
|
} else |
|
|
|
} else |
|
|
|
keep_sockalive(cs->fd); |
|
|
|
keep_sockalive(cs->fd); |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
@ -1421,8 +1415,7 @@ static void kill_proxy(ckpool_t *ckp, proxy_instance_t *proxi) |
|
|
|
|
|
|
|
|
|
|
|
LOGNOTICE("Killing proxy"); |
|
|
|
LOGNOTICE("Killing proxy"); |
|
|
|
cs = proxi->cs; |
|
|
|
cs = proxi->cs; |
|
|
|
close(cs->fd); |
|
|
|
Close(cs->fd); |
|
|
|
cs->fd = -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* All our notify data is invalid if we reconnect so discard them */ |
|
|
|
/* All our notify data is invalid if we reconnect so discard them */ |
|
|
|
mutex_lock(&proxi->notify_lock); |
|
|
|
mutex_lock(&proxi->notify_lock); |
|
|
@ -1495,7 +1488,7 @@ retry: |
|
|
|
buf = recv_unix_msg(sockd); |
|
|
|
buf = recv_unix_msg(sockd); |
|
|
|
if (!buf) { |
|
|
|
if (!buf) { |
|
|
|
LOGWARNING("Failed to get message in proxy_loop"); |
|
|
|
LOGWARNING("Failed to get message in proxy_loop"); |
|
|
|
close(sockd); |
|
|
|
Close(sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
LOGDEBUG("Proxy received request: %s", buf); |
|
|
|
LOGDEBUG("Proxy received request: %s", buf); |
|
|
@ -1503,11 +1496,11 @@ retry: |
|
|
|
ret = 0; |
|
|
|
ret = 0; |
|
|
|
goto out; |
|
|
|
goto out; |
|
|
|
} else if (cmdmatch(buf, "getsubscribe")) { |
|
|
|
} else if (cmdmatch(buf, "getsubscribe")) { |
|
|
|
send_subscribe(proxi, sockd); |
|
|
|
send_subscribe(proxi, &sockd); |
|
|
|
} else if (cmdmatch(buf, "getnotify")) { |
|
|
|
} else if (cmdmatch(buf, "getnotify")) { |
|
|
|
send_notify(proxi, sockd); |
|
|
|
send_notify(proxi, &sockd); |
|
|
|
} else if (cmdmatch(buf, "getdiff")) { |
|
|
|
} else if (cmdmatch(buf, "getdiff")) { |
|
|
|
send_diff(proxi, sockd); |
|
|
|
send_diff(proxi, &sockd); |
|
|
|
} else if (cmdmatch(buf, "reconnect")) { |
|
|
|
} else if (cmdmatch(buf, "reconnect")) { |
|
|
|
goto reconnect; |
|
|
|
goto reconnect; |
|
|
|
} else if (cmdmatch(buf, "submitblock:")) { |
|
|
|
} else if (cmdmatch(buf, "submitblock:")) { |
|
|
@ -1536,11 +1529,11 @@ retry: |
|
|
|
else |
|
|
|
else |
|
|
|
submit_share(proxi, val); |
|
|
|
submit_share(proxi, val); |
|
|
|
} |
|
|
|
} |
|
|
|
close(sockd); |
|
|
|
Close(sockd); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
out: |
|
|
|
out: |
|
|
|
kill_proxy(ckp, proxi); |
|
|
|
kill_proxy(ckp, proxi); |
|
|
|
close(sockd); |
|
|
|
Close(sockd); |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1653,7 +1646,7 @@ static int proxy_mode(ckpool_t *ckp, proc_instance_t *pi) |
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ckp->proxies; i++) { |
|
|
|
for (i = 0; i < ckp->proxies; i++) { |
|
|
|
si = ckp->servers[i]; |
|
|
|
si = ckp->servers[i]; |
|
|
|
close(si->cs.fd); |
|
|
|
Close(si->cs.fd); |
|
|
|
proxi = si->data; |
|
|
|
proxi = si->data; |
|
|
|
free(proxi->enonce1); |
|
|
|
free(proxi->enonce1); |
|
|
|
free(proxi->enonce1bin); |
|
|
|
free(proxi->enonce1bin); |
|
|
|