|
|
@ -188,8 +188,10 @@ out: |
|
|
|
if (!ret) { |
|
|
|
if (!ret) { |
|
|
|
/* Close and invalidate the file handle */ |
|
|
|
/* Close and invalidate the file handle */ |
|
|
|
Close(cs->fd); |
|
|
|
Close(cs->fd); |
|
|
|
} else |
|
|
|
} else { |
|
|
|
|
|
|
|
LOGNOTICE("Server alive: %s:%s", cs->url, cs->port); |
|
|
|
keep_sockalive(cs->fd); |
|
|
|
keep_sockalive(cs->fd); |
|
|
|
|
|
|
|
} |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -244,9 +246,8 @@ static void kill_server(server_instance_t *si) |
|
|
|
|
|
|
|
|
|
|
|
static int gen_loop(proc_instance_t *pi) |
|
|
|
static int gen_loop(proc_instance_t *pi) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
server_instance_t *si = NULL, *old_si; |
|
|
|
int sockd = -1, ret = 0, selret; |
|
|
|
int sockd = -1, ret = 0, selret; |
|
|
|
server_instance_t *si = NULL; |
|
|
|
|
|
|
|
bool reconnecting = false; |
|
|
|
|
|
|
|
unixsock_t *us = &pi->us; |
|
|
|
unixsock_t *us = &pi->us; |
|
|
|
ckpool_t *ckp = pi->ckp; |
|
|
|
ckpool_t *ckp = pi->ckp; |
|
|
|
gdata_t *gdata = ckp->data; |
|
|
|
gdata_t *gdata = ckp->data; |
|
|
@ -258,20 +259,17 @@ static int gen_loop(proc_instance_t *pi) |
|
|
|
|
|
|
|
|
|
|
|
reconnect: |
|
|
|
reconnect: |
|
|
|
Close(sockd); |
|
|
|
Close(sockd); |
|
|
|
if (si) { |
|
|
|
old_si = si; |
|
|
|
kill_server(si); |
|
|
|
|
|
|
|
reconnecting = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
si = live_server(ckp); |
|
|
|
si = live_server(ckp); |
|
|
|
if (!si) |
|
|
|
if (!si) |
|
|
|
goto out; |
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
|
|
gbt = si->data; |
|
|
|
gbt = si->data; |
|
|
|
cs = &si->cs; |
|
|
|
cs = &si->cs; |
|
|
|
if (reconnecting) { |
|
|
|
if (!old_si) |
|
|
|
|
|
|
|
LOGWARNING("Connected to bitoind: %s:%s", cs->url, cs->port); |
|
|
|
|
|
|
|
else if (si != old_si) |
|
|
|
LOGWARNING("Failed over to bitcoind: %s:%s", cs->url, cs->port); |
|
|
|
LOGWARNING("Failed over to bitcoind: %s:%s", cs->url, cs->port); |
|
|
|
reconnecting = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
retry: |
|
|
|
retry: |
|
|
|
Close(sockd); |
|
|
|
Close(sockd); |
|
|
@ -1698,6 +1696,7 @@ static int server_mode(ckpool_t *ckp, proc_instance_t *pi) |
|
|
|
si->auth = ckp->btcdauth[i]; |
|
|
|
si->auth = ckp->btcdauth[i]; |
|
|
|
si->pass = ckp->btcdpass[i]; |
|
|
|
si->pass = ckp->btcdpass[i]; |
|
|
|
si->notify = ckp->btcdnotify[i]; |
|
|
|
si->notify = ckp->btcdnotify[i]; |
|
|
|
|
|
|
|
si->id = i; |
|
|
|
cksem_init(&si->cs.sem); |
|
|
|
cksem_init(&si->cs.sem); |
|
|
|
cksem_post(&si->cs.sem); |
|
|
|
cksem_post(&si->cs.sem); |
|
|
|
} |
|
|
|
} |
|
|
@ -1770,12 +1769,13 @@ static int proxy_mode(ckpool_t *ckp, proc_instance_t *pi) |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Tell the watchdog what the current server instance is and decide if we
|
|
|
|
/* Tell the watchdog what the current server instance is, check which servers
|
|
|
|
* should check to see if the higher priority servers are alive and fallback */ |
|
|
|
* are alive, maintaining a connection with them and reconnect if a higher |
|
|
|
|
|
|
|
* priority one is available. */ |
|
|
|
static void server_watchdog(ckpool_t *ckp, server_instance_t *cursi) |
|
|
|
static void server_watchdog(ckpool_t *ckp, server_instance_t *cursi) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
server_instance_t *best = NULL; |
|
|
|
static time_t last_t = 0; |
|
|
|
static time_t last_t = 0; |
|
|
|
bool alive = false; |
|
|
|
|
|
|
|
time_t now_t; |
|
|
|
time_t now_t; |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
@ -1786,22 +1786,14 @@ static void server_watchdog(ckpool_t *ckp, server_instance_t *cursi) |
|
|
|
|
|
|
|
|
|
|
|
last_t = now_t; |
|
|
|
last_t = now_t; |
|
|
|
|
|
|
|
|
|
|
|
/* Is this the highest priority server already? */ |
|
|
|
|
|
|
|
if (!cursi->id) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ckp->btcds; i++) { |
|
|
|
for (i = 0; i < ckp->btcds; i++) { |
|
|
|
server_instance_t *si = ckp->servers[i]; |
|
|
|
server_instance_t *si = ckp->servers[i]; |
|
|
|
|
|
|
|
|
|
|
|
/* Have we reached the current server? */ |
|
|
|
/* Have we reached the current server? */ |
|
|
|
if (si == cursi) |
|
|
|
if (server_alive(ckp, si, true) && !best) |
|
|
|
return; |
|
|
|
best = si; |
|
|
|
|
|
|
|
|
|
|
|
alive = server_alive(ckp, si, true); |
|
|
|
|
|
|
|
if (alive) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (alive) |
|
|
|
if (best && (!cursi || cursi->id > best->id)) |
|
|
|
send_proc(ckp->generator, "reconnect"); |
|
|
|
send_proc(ckp->generator, "reconnect"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|