|
|
@ -1389,6 +1389,15 @@ retry: |
|
|
|
pthread_cancel(proxi->pth_precv); |
|
|
|
pthread_cancel(proxi->pth_precv); |
|
|
|
pthread_cancel(proxi->pth_psend); |
|
|
|
pthread_cancel(proxi->pth_psend); |
|
|
|
goto reconnect; |
|
|
|
goto reconnect; |
|
|
|
|
|
|
|
} else if (cmdmatch(buf, "submitblock:")) { |
|
|
|
|
|
|
|
if (ckp->btcdbackup) { |
|
|
|
|
|
|
|
LOGWARNING("Submitting block data locally!"); |
|
|
|
|
|
|
|
if (submit_block(&ckp->btcdbackup->cs, buf + 12)) |
|
|
|
|
|
|
|
LOGWARNING("Block accepted locally!"); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
LOGWARNING("Block rejected locally."); |
|
|
|
|
|
|
|
} else |
|
|
|
|
|
|
|
LOGNOTICE("No backup btcd to send block to ourselves"); |
|
|
|
} else if (cmdmatch(buf, "loglevel")) { |
|
|
|
} else if (cmdmatch(buf, "loglevel")) { |
|
|
|
sscanf(buf, "loglevel=%d", &ckp->loglevel); |
|
|
|
sscanf(buf, "loglevel=%d", &ckp->loglevel); |
|
|
|
} else if (cmdmatch(buf, "ping")) { |
|
|
|
} else if (cmdmatch(buf, "ping")) { |
|
|
@ -1439,6 +1448,42 @@ static int server_mode(ckpool_t *ckp, proc_instance_t *pi) |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool alive_btcd(server_instance_t *si) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
connsock_t *cs = &si->cs; |
|
|
|
|
|
|
|
char *userpass = NULL; |
|
|
|
|
|
|
|
gbtbase_t gbt; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!extract_sockaddr(si->url, &cs->url, &cs->port)) { |
|
|
|
|
|
|
|
LOGWARNING("Failed to extract address from btcd %s", si->url); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
userpass = strdup(si->auth); |
|
|
|
|
|
|
|
realloc_strcat(&userpass, ":"); |
|
|
|
|
|
|
|
realloc_strcat(&userpass, si->pass); |
|
|
|
|
|
|
|
cs->auth = http_base64(userpass); |
|
|
|
|
|
|
|
dealloc(userpass); |
|
|
|
|
|
|
|
if (!cs->auth) { |
|
|
|
|
|
|
|
LOGWARNING("Failed to create base64 auth from btcd %s", userpass); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cs->fd = connect_socket(cs->url, cs->port); |
|
|
|
|
|
|
|
if (cs->fd < 0) { |
|
|
|
|
|
|
|
LOGWARNING("Failed to connect socket to btcd %s:%s !", cs->url, cs->port); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
keep_sockalive(cs->fd); |
|
|
|
|
|
|
|
/* Test we can authorise by getting a gbt, but we won't be using it. */ |
|
|
|
|
|
|
|
memset(&gbt, 0, sizeof(gbtbase_t)); |
|
|
|
|
|
|
|
if (!gen_gbtbase(cs, &gbt)) { |
|
|
|
|
|
|
|
LOGINFO("Failed to get test block template from btcd %s:%s!", |
|
|
|
|
|
|
|
cs->url, cs->port); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
clear_gbtbase(&gbt); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int proxy_mode(ckpool_t *ckp, proc_instance_t *pi) |
|
|
|
static int proxy_mode(ckpool_t *ckp, proc_instance_t *pi) |
|
|
|
{ |
|
|
|
{ |
|
|
|
proxy_instance_t *proxi; |
|
|
|
proxy_instance_t *proxi; |
|
|
@ -1463,6 +1508,23 @@ static int proxy_mode(ckpool_t *ckp, proc_instance_t *pi) |
|
|
|
proxi->cs = &si->cs; |
|
|
|
proxi->cs = &si->cs; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ckp->btcds) { |
|
|
|
|
|
|
|
/* If we also have btcds set up in proxy mode, try to talk to
|
|
|
|
|
|
|
|
* one of them as a way to submit blocks if we find them when |
|
|
|
|
|
|
|
* submitting them upstream. */ |
|
|
|
|
|
|
|
si = ckp->btcdbackup = ckzalloc(sizeof(server_instance_t)); |
|
|
|
|
|
|
|
si->url = ckp->btcdurl[0]; |
|
|
|
|
|
|
|
si->auth = ckp->btcdauth[0]; |
|
|
|
|
|
|
|
si->pass = ckp->btcdpass[0]; |
|
|
|
|
|
|
|
if (alive_btcd(si)) |
|
|
|
|
|
|
|
LOGNOTICE("Backup btcd %s:%s alive", si->cs.url, si->cs.port); |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
LOGWARNING("Backup btcd %s:%s failed!", si->cs.url, si->cs.port); |
|
|
|
|
|
|
|
ckp->btcdbackup = NULL; |
|
|
|
|
|
|
|
free(si); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LOGWARNING("%s generator ready", ckp->name); |
|
|
|
LOGWARNING("%s generator ready", ckp->name); |
|
|
|
|
|
|
|
|
|
|
|
ret = proxy_loop(pi); |
|
|
|
ret = proxy_loop(pi); |
|
|
|