Add some default parameters to make polling intervals configurable
This commit is contained in:
parent
2bcdc4bcce
commit
8f0958bbfb
32
src/ckpool.c
32
src/ckpool.c
@ -168,7 +168,7 @@ static void json_get_string(char **store, json_t *val, const char *res)
|
||||
return;
|
||||
}
|
||||
if (!json_is_string(entry)) {
|
||||
LOGWARNING("Json entry %s is not string", res);
|
||||
LOGWARNING("Json entry %s is not a string", res);
|
||||
return;
|
||||
}
|
||||
buf = json_string_value(entry);
|
||||
@ -176,6 +176,21 @@ static void json_get_string(char **store, json_t *val, const char *res)
|
||||
*store = strdup(buf);
|
||||
}
|
||||
|
||||
static void json_get_int(int *store, json_t *val, const char *res)
|
||||
{
|
||||
json_t *entry = json_object_get(val, res);
|
||||
|
||||
if (!entry) {
|
||||
LOGDEBUG("Json did not find entry %s", res);
|
||||
return;
|
||||
}
|
||||
if (!json_is_integer(entry)) {
|
||||
LOGWARNING("Json entry %s is not an integer", res);
|
||||
return;
|
||||
}
|
||||
*store = json_integer_value(entry);
|
||||
}
|
||||
|
||||
static void parse_config(ckpool_t *ckp)
|
||||
{
|
||||
json_error_t err_val;
|
||||
@ -192,6 +207,8 @@ static void parse_config(ckpool_t *ckp)
|
||||
json_get_string(&ckp->btcdpass, json_conf, "btcdpass");
|
||||
json_get_string(&ckp->btcaddress, json_conf, "btcaddress");
|
||||
json_get_string(&ckp->btcsig, json_conf, "btcsig");
|
||||
json_get_int(&ckp->blockpoll, json_conf, "blockpoll");
|
||||
json_get_int(&ckp->update_interval, json_conf, "update_interval");
|
||||
json_decref(json_conf);
|
||||
}
|
||||
|
||||
@ -303,6 +320,19 @@ int main(int argc, char **argv)
|
||||
quit(1, "Failed to make directory %s", ckp.socket_dir);
|
||||
|
||||
parse_config(&ckp);
|
||||
/* Set defaults if not found in config file */
|
||||
if (!ckp.btcdurl)
|
||||
ckp.btcdurl = strdup("localhost:8332");
|
||||
if (!ckp.btcdauth)
|
||||
ckp.btcdauth = strdup("user");
|
||||
if (!ckp.btcdpass)
|
||||
ckp.btcdpass = strdup("pass");
|
||||
if (!ckp.btcaddress)
|
||||
ckp.btcaddress = strdup("15qSxP1SQcUX3o4nhkfdbgyoWEFMomJ4rZ");
|
||||
if (!ckp.blockpoll)
|
||||
ckp.blockpoll = 500;
|
||||
if (!ckp.update_interval)
|
||||
ckp.update_interval = 30;
|
||||
|
||||
ckp.main.ckp = &ckp;
|
||||
ckp.main.processname = strdup("main");
|
||||
|
||||
@ -78,12 +78,6 @@ int generator(proc_instance_t *pi)
|
||||
memset(&cs, 0, sizeof(cs));
|
||||
memset(&gbt, 0, sizeof(gbt));
|
||||
|
||||
if (!ckp->btcdurl)
|
||||
ckp->btcdurl = strdup("localhost:8332");
|
||||
if (!ckp->btcdauth)
|
||||
ckp->btcdauth = strdup("user");
|
||||
if (!ckp->btcdpass)
|
||||
ckp->btcdpass = strdup("pass");
|
||||
if (!extract_sockaddr(ckp->btcdurl, &cs.url, &cs.port)) {
|
||||
LOGWARNING("Failed to extract address from %s", ckp->btcdurl);
|
||||
ret = 1;
|
||||
|
||||
@ -158,8 +158,14 @@ struct ckpool_instance {
|
||||
char *btcdurl;
|
||||
char *btcdauth;
|
||||
char *btcdpass;
|
||||
char *btcaddress;
|
||||
char *btcsig;
|
||||
int blockpoll; // How frequently in ms to poll bitcoind for block updates
|
||||
|
||||
/* Coinbase data */
|
||||
char *btcaddress; // Address to mine to
|
||||
char *btcsig; // Optional signature to add to coinbase
|
||||
|
||||
/* Stratum options */
|
||||
int update_interval; // Seconds between stratum updates
|
||||
};
|
||||
|
||||
void create_pthread(pthread_t *thread, void *(*start_routine)(void *), void *arg);
|
||||
|
||||
@ -237,7 +237,7 @@ static int strat_loop(ckpool_t *ckp, proc_instance_t *pi)
|
||||
tv_t timeout;
|
||||
|
||||
reset:
|
||||
timeout.tv_sec = 60;
|
||||
timeout.tv_sec = ckp->update_interval;
|
||||
retry:
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(us->sockd, &readfds);
|
||||
@ -250,7 +250,7 @@ retry:
|
||||
goto out;
|
||||
}
|
||||
if (!selret) {
|
||||
LOGDEBUG("60s elapsed in strat_loop, updating gbt base");
|
||||
LOGDEBUG("%ds elapsed in strat_loop, updating gbt base", ckp->update_interval);
|
||||
update_base(ckp);
|
||||
goto reset;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user