diff --git a/src/ckpool.c b/src/ckpool.c index 4989f0e6..adc3a5d0 100644 --- a/src/ckpool.c +++ b/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"); diff --git a/src/generator.c b/src/generator.c index 2c3ba43b..b7a21770 100644 --- a/src/generator.c +++ b/src/generator.c @@ -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; diff --git a/src/libckpool.h b/src/libckpool.h index 10a4f21f..da373f5c 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -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); diff --git a/src/stratifier.c b/src/stratifier.c index ce79d976..4e188cf5 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -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; }