Browse Source

Allow serverurl to take an array of entries for future binding to multiple interfaces/ports

master
Con Kolivas 10 years ago
parent
commit
5dd076cfbe
  1. 57
      src/ckpool.c
  2. 3
      src/ckpool.h
  3. 6
      src/connector.c
  4. 20
      src/stratifier.c

57
src/ckpool.c

@ -890,9 +890,8 @@ static void sighandler(int sig)
exit(0); exit(0);
} }
bool json_get_string(char **store, json_t *val, const char *res) static bool _json_get_string(char **store, json_t *entry, const char *res)
{ {
json_t *entry = json_object_get(val, res);
bool ret = false; bool ret = false;
const char *buf; const char *buf;
@ -913,6 +912,11 @@ out:
return ret; return ret;
} }
bool json_get_string(char **store, json_t *val, const char *res)
{
return _json_get_string(store, json_object_get(val, res), res);
}
static void json_get_int64(int64_t *store, json_t *val, const char *res) static void json_get_int64(int64_t *store, json_t *val, const char *res)
{ {
json_t *entry = json_object_get(val, res); json_t *entry = json_object_get(val, res);
@ -1005,10 +1009,41 @@ static void parse_proxies(ckpool_t *ckp, json_t *arr_val, int arr_size)
} }
} }
static bool parse_serverurls(ckpool_t *ckp, json_t *arr_val)
{
bool ret = false;
int arr_size, i;
if (!arr_val)
goto out;
if (!json_is_array(arr_val)) {
LOGWARNING("Unable to parse serverurl entries as an array");
goto out;
}
arr_size = json_array_size(arr_val);
if (!arr_size) {
LOGWARNING("Serverurl array empty");
goto out;
}
ckp->serverurls = arr_size;
ckp->serverurl = ckalloc(sizeof(char *) * arr_size);
for (i = 0; i < arr_size; i++) {
json_t *val = json_array_get(arr_val, i);
if (!_json_get_string(&ckp->serverurl[i], val, "serverurl"))
LOGWARNING("Invalid serverurl entry number %d", i);
}
ret = true;
out:
return ret;
}
static void parse_config(ckpool_t *ckp) static void parse_config(ckpool_t *ckp)
{ {
json_t *json_conf, *arr_val; json_t *json_conf, *arr_val;
json_error_t err_val; json_error_t err_val;
int arr_size;
char *url;
json_conf = json_load_file(ckp->config, JSON_DISABLE_EOF_CHECK, &err_val); json_conf = json_load_file(ckp->config, JSON_DISABLE_EOF_CHECK, &err_val);
if (!json_conf) { if (!json_conf) {
@ -1018,8 +1053,7 @@ static void parse_config(ckpool_t *ckp)
} }
arr_val = json_object_get(json_conf, "btcd"); arr_val = json_object_get(json_conf, "btcd");
if (arr_val && json_is_array(arr_val)) { if (arr_val && json_is_array(arr_val)) {
int arr_size = json_array_size(arr_val); arr_size = json_array_size(arr_val);
if (arr_size) if (arr_size)
parse_btcds(ckp, arr_val, arr_size); parse_btcds(ckp, arr_val, arr_size);
} }
@ -1033,7 +1067,15 @@ static void parse_config(ckpool_t *ckp)
json_get_int(&ckp->nonce1length, json_conf, "nonce1length"); json_get_int(&ckp->nonce1length, json_conf, "nonce1length");
json_get_int(&ckp->nonce2length, json_conf, "nonce2length"); json_get_int(&ckp->nonce2length, json_conf, "nonce2length");
json_get_int(&ckp->update_interval, json_conf, "update_interval"); json_get_int(&ckp->update_interval, json_conf, "update_interval");
json_get_string(&ckp->serverurl, json_conf, "serverurl"); /* Look for an array first and then a single entry */
arr_val = json_object_get(json_conf, "serverurl");
if (!parse_serverurls(ckp, arr_val)) {
if (json_get_string(&url, json_conf, "serverurl")) {
ckp->serverurl = ckalloc(sizeof(char *));
ckp->serverurl[0] = url;
ckp->serverurls = 1;
}
}
json_get_int64(&ckp->mindiff, json_conf, "mindiff"); json_get_int64(&ckp->mindiff, json_conf, "mindiff");
json_get_int64(&ckp->startdiff, json_conf, "startdiff"); json_get_int64(&ckp->startdiff, json_conf, "startdiff");
json_get_int64(&ckp->maxdiff, json_conf, "maxdiff"); json_get_int64(&ckp->maxdiff, json_conf, "maxdiff");
@ -1041,8 +1083,7 @@ static void parse_config(ckpool_t *ckp)
json_get_int(&ckp->maxclients, json_conf, "maxclients"); json_get_int(&ckp->maxclients, json_conf, "maxclients");
arr_val = json_object_get(json_conf, "proxy"); arr_val = json_object_get(json_conf, "proxy");
if (arr_val && json_is_array(arr_val)) { if (arr_val && json_is_array(arr_val)) {
int arr_size = json_array_size(arr_val); arr_size = json_array_size(arr_val);
if (arr_size) if (arr_size)
parse_proxies(ckp, arr_val, arr_size); parse_proxies(ckp, arr_val, arr_size);
} }
@ -1342,6 +1383,8 @@ int main(int argc, char **argv)
ckp.startdiff = 42; ckp.startdiff = 42;
if (!ckp.logdir) if (!ckp.logdir)
ckp.logdir = strdup("logs"); ckp.logdir = strdup("logs");
if (!ckp.serverurls)
ckp.serverurl = ckzalloc(sizeof(char *));
if (ckp.proxy && !ckp.proxies) if (ckp.proxy && !ckp.proxies)
quit(0, "No proxy entries found in config file %s", ckp.config); quit(0, "No proxy entries found in config file %s", ckp.config);

3
src/ckpool.h

@ -164,7 +164,8 @@ struct ckpool_instance {
/* Stratum options */ /* Stratum options */
server_instance_t **servers; server_instance_t **servers;
char *serverurl; // URL to bind our server/proxy to char **serverurl; // Array of URLs to bind our server/proxy to
int serverurls; // Number of server bindings
int update_interval; // Seconds between stratum updates int update_interval; // Seconds between stratum updates
int chosen_server; // Chosen server for next connection int chosen_server; // Chosen server for next connection

6
src/connector.c

@ -742,9 +742,9 @@ int connector(proc_instance_t *pi)
if (ckp->oldconnfd > 0) { if (ckp->oldconnfd > 0) {
sockd = ckp->oldconnfd; sockd = ckp->oldconnfd;
} else if (ckp->serverurl) { } else if (ckp->serverurls && ckp->serverurl[0]) {
if (!extract_sockaddr(ckp->serverurl, &url, &port)) { if (!extract_sockaddr(ckp->serverurl[0], &url, &port)) {
LOGWARNING("Failed to extract server address from %s", ckp->serverurl); LOGWARNING("Failed to extract server address from %s", ckp->serverurl[0]);
ret = 1; ret = 1;
goto out; goto out;
} }

20
src/stratifier.c

@ -603,7 +603,7 @@ static void send_workinfo(ckpool_t *ckp, workbase_t *wb)
"createdate", cdfield, "createdate", cdfield,
"createby", "code", "createby", "code",
"createcode", __func__, "createcode", __func__,
"createinet", ckp->serverurl); "createinet", ckp->serverurl[0]);
ckdbq_add(ckp, ID_WORKINFO, val); ckdbq_add(ckp, ID_WORKINFO, val);
} }
@ -622,7 +622,7 @@ static void send_ageworkinfo(ckpool_t *ckp, int64_t id)
"createdate", cdfield, "createdate", cdfield,
"createby", "code", "createby", "code",
"createcode", __func__, "createcode", __func__,
"createinet", ckp->serverurl); "createinet", ckp->serverurl[0]);
ckdbq_add(ckp, ID_AGEWORKINFO, val); ckdbq_add(ckp, ID_AGEWORKINFO, val);
} }
@ -2304,7 +2304,7 @@ test_blocksolve(stratum_instance_t *client, workbase_t *wb, const uchar *data, c
"createdate", cdfield, "createdate", cdfield,
"createby", "code", "createby", "code",
"createcode", __func__, "createcode", __func__,
"createinet", ckp->serverurl); "createinet", ckp->serverurl[0]);
val_copy = json_deep_copy(val); val_copy = json_deep_copy(val);
block_ckmsg = ckalloc(sizeof(ckmsg_t)); block_ckmsg = ckalloc(sizeof(ckmsg_t));
block_ckmsg->data = val_copy; block_ckmsg->data = val_copy;
@ -2604,7 +2604,7 @@ out_unlock:
json_set_string(val, "createdate", cdfield); json_set_string(val, "createdate", cdfield);
json_set_string(val, "createby", "code"); json_set_string(val, "createby", "code");
json_set_string(val, "createcode", __func__); json_set_string(val, "createcode", __func__);
json_set_string(val, "createinet", ckp->serverurl); json_set_string(val, "createinet", ckp->serverurl[0]);
json_set_string(val, "workername", client->workername); json_set_string(val, "workername", client->workername);
json_set_string(val, "username", user_instance->username); json_set_string(val, "username", user_instance->username);
@ -2656,7 +2656,7 @@ out:
"createdate", cdfield, "createdate", cdfield,
"createby", "code", "createby", "code",
"createcode", __func__, "createcode", __func__,
"createinet", ckp->serverurl); "createinet", ckp->serverurl[0]);
ckdbq_add(ckp, ID_SHAREERR, val); ckdbq_add(ckp, ID_SHAREERR, val);
LOGINFO("Invalid share from client %ld: %s", client->id, client->workername); LOGINFO("Invalid share from client %ld: %s", client->id, client->workername);
} }
@ -3595,7 +3595,7 @@ static void *statsupdate(void *arg)
"createdate", cdfield, "createdate", cdfield,
"createby", "code", "createby", "code",
"createcode", __func__, "createcode", __func__,
"createinet", ckp->serverurl); "createinet", ckp->serverurl[0]);
ckdbq_add(ckp, ID_POOLSTATS, val); ckdbq_add(ckp, ID_POOLSTATS, val);
/* Update stats 3 times per minute for smooth values, displaying /* Update stats 3 times per minute for smooth values, displaying
@ -3660,7 +3660,7 @@ static void *ckdb_heartbeat(void *arg)
"createdate", cdfield, "createdate", cdfield,
"createby", "code", "createby", "code",
"createcode", __func__, "createcode", __func__,
"createinet", ckp->serverurl); "createinet", ckp->serverurl[0]);
ckdbq_add(ckp, ID_HEARTBEAT, val); ckdbq_add(ckp, ID_HEARTBEAT, val);
} }
return NULL; return NULL;
@ -3713,8 +3713,10 @@ int stratifier(proc_instance_t *pi)
dealloc(buf); dealloc(buf);
if (!ckp->serverurl) if (!ckp->serverurls) {
ckp->serverurl = "127.0.0.1"; ckp->serverurl[0] = "127.0.0.1";
ckp->serverurls = 1;
}
cklock_init(&sdata->instance_lock); cklock_init(&sdata->instance_lock);
mutex_init(&sdata->ckdb_lock); mutex_init(&sdata->ckdb_lock);

Loading…
Cancel
Save