Browse Source

Add some default parameters to make polling intervals configurable

master
Con Kolivas 11 years ago
parent
commit
8f0958bbfb
  1. 32
      src/ckpool.c
  2. 6
      src/generator.c
  3. 10
      src/libckpool.h
  4. 4
      src/stratifier.c

32
src/ckpool.c

@ -168,7 +168,7 @@ static void json_get_string(char **store, json_t *val, const char *res)
return; return;
} }
if (!json_is_string(entry)) { if (!json_is_string(entry)) {
LOGWARNING("Json entry %s is not string", res); LOGWARNING("Json entry %s is not a string", res);
return; return;
} }
buf = json_string_value(entry); 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); *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) static void parse_config(ckpool_t *ckp)
{ {
json_error_t err_val; 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->btcdpass, json_conf, "btcdpass");
json_get_string(&ckp->btcaddress, json_conf, "btcaddress"); json_get_string(&ckp->btcaddress, json_conf, "btcaddress");
json_get_string(&ckp->btcsig, json_conf, "btcsig"); 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); json_decref(json_conf);
} }
@ -303,6 +320,19 @@ int main(int argc, char **argv)
quit(1, "Failed to make directory %s", ckp.socket_dir); quit(1, "Failed to make directory %s", ckp.socket_dir);
parse_config(&ckp); 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.ckp = &ckp;
ckp.main.processname = strdup("main"); ckp.main.processname = strdup("main");

6
src/generator.c

@ -78,12 +78,6 @@ int generator(proc_instance_t *pi)
memset(&cs, 0, sizeof(cs)); memset(&cs, 0, sizeof(cs));
memset(&gbt, 0, sizeof(gbt)); 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)) { if (!extract_sockaddr(ckp->btcdurl, &cs.url, &cs.port)) {
LOGWARNING("Failed to extract address from %s", ckp->btcdurl); LOGWARNING("Failed to extract address from %s", ckp->btcdurl);
ret = 1; ret = 1;

10
src/libckpool.h

@ -158,8 +158,14 @@ struct ckpool_instance {
char *btcdurl; char *btcdurl;
char *btcdauth; char *btcdauth;
char *btcdpass; char *btcdpass;
char *btcaddress; int blockpoll; // How frequently in ms to poll bitcoind for block updates
char *btcsig;
/* 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); void create_pthread(pthread_t *thread, void *(*start_routine)(void *), void *arg);

4
src/stratifier.c

@ -237,7 +237,7 @@ static int strat_loop(ckpool_t *ckp, proc_instance_t *pi)
tv_t timeout; tv_t timeout;
reset: reset:
timeout.tv_sec = 60; timeout.tv_sec = ckp->update_interval;
retry: retry:
FD_ZERO(&readfds); FD_ZERO(&readfds);
FD_SET(us->sockd, &readfds); FD_SET(us->sockd, &readfds);
@ -250,7 +250,7 @@ retry:
goto out; goto out;
} }
if (!selret) { 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); update_base(ckp);
goto reset; goto reset;
} }

Loading…
Cancel
Save