Browse Source

Add variable parsing for trusted remote nodes

master
Con Kolivas 9 years ago
parent
commit
bd7ca390ff
  1. 6
      ckpool.conf
  2. 44
      src/ckpool.c
  3. 5
      src/ckpool.h

6
ckpool.conf

@ -13,6 +13,9 @@
"notify" : false "notify" : false
} }
], ],
"upstream" : {
"url" : "main.ckpool.org:3336"
},
"btcaddress" : "14BMjogz69qe8hk9thyzbmR5pg34mVKB1e", "btcaddress" : "14BMjogz69qe8hk9thyzbmR5pg34mVKB1e",
"btcsig" : "/mined by ck/", "btcsig" : "/mined by ck/",
"blockpoll" : 100, "blockpoll" : 100,
@ -27,6 +30,9 @@
"nodeserver" : [ "nodeserver" : [
"ckpool.org:3335" "ckpool.org:3335"
], ],
"trusted" : [
"ckpool.org:3336"
],
"mindiff" : 1, "mindiff" : 1,
"startdiff" : 42, "startdiff" : 42,
"maxdiff" : 0, "maxdiff" : 0,

44
src/ckpool.c

@ -1297,6 +1297,7 @@ static bool parse_serverurls(ckpool_t *ckp, const json_t *arr_val)
ckp->serverurls = arr_size; ckp->serverurls = arr_size;
ckp->serverurl = ckalloc(sizeof(char *) * arr_size); ckp->serverurl = ckalloc(sizeof(char *) * arr_size);
ckp->nodeserver = ckzalloc(sizeof(bool) * arr_size); ckp->nodeserver = ckzalloc(sizeof(bool) * arr_size);
ckp->trusted = ckzalloc(sizeof(bool) * arr_size);
for (i = 0; i < arr_size; i++) { for (i = 0; i < arr_size; i++) {
json_t *val = json_array_get(arr_val, i); json_t *val = json_array_get(arr_val, i);
@ -1326,6 +1327,7 @@ static void parse_nodeservers(ckpool_t *ckp, const json_t *arr_val)
total_urls = ckp->serverurls + arr_size; total_urls = ckp->serverurls + arr_size;
ckp->serverurl = realloc(ckp->serverurl, sizeof(char *) * total_urls); ckp->serverurl = realloc(ckp->serverurl, sizeof(char *) * total_urls);
ckp->nodeserver = realloc(ckp->nodeserver, sizeof(bool) * total_urls); ckp->nodeserver = realloc(ckp->nodeserver, sizeof(bool) * total_urls);
ckp->trusted = realloc(ckp->trusted, sizeof(bool) * total_urls);
for (i = 0, j = ckp->serverurls; j < total_urls; i++, j++) { for (i = 0, j = ckp->serverurls; j < total_urls; i++, j++) {
json_t *val = json_array_get(arr_val, i); json_t *val = json_array_get(arr_val, i);
@ -1336,6 +1338,36 @@ static void parse_nodeservers(ckpool_t *ckp, const json_t *arr_val)
ckp->serverurls = total_urls; ckp->serverurls = total_urls;
} }
static void parse_trusted(ckpool_t *ckp, const json_t *arr_val)
{
int arr_size, i, j, total_urls;
if (!arr_val)
return;
if (!json_is_array(arr_val)) {
LOGWARNING("Unable to parse trusted server entries as an array");
return;
}
arr_size = json_array_size(arr_val);
if (!arr_size) {
LOGWARNING("Trusted array empty");
return;
}
total_urls = ckp->serverurls + arr_size;
ckp->serverurl = realloc(ckp->serverurl, sizeof(char *) * total_urls);
ckp->nodeserver = realloc(ckp->nodeserver, sizeof(bool) * total_urls);
ckp->trusted = realloc(ckp->trusted, sizeof(bool) * total_urls);
for (i = 0, j = ckp->serverurls; j < total_urls; i++, j++) {
json_t *val = json_array_get(arr_val, i);
if (!_json_get_string(&ckp->serverurl[j], val, "trusted"))
LOGWARNING("Invalid trusted server entry number %d", i);
ckp->trusted[j] = true;
}
ckp->serverurls = total_urls;
}
static bool parse_redirecturls(ckpool_t *ckp, const json_t *arr_val) static bool parse_redirecturls(ckpool_t *ckp, const json_t *arr_val)
{ {
bool ret = false; bool ret = false;
@ -1413,6 +1445,9 @@ static void parse_config(ckpool_t *ckp)
} }
arr_val = json_object_get(json_conf, "nodeserver"); arr_val = json_object_get(json_conf, "nodeserver");
parse_nodeservers(ckp, arr_val); parse_nodeservers(ckp, arr_val);
arr_val = json_object_get(json_conf, "trusted");
parse_trusted(ckp, arr_val);
json_get_string(&ckp->upstream, json_conf, "upstream");
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");
@ -1559,6 +1594,7 @@ static struct option long_options[] = {
{"redirector", no_argument, 0, 'R'}, {"redirector", no_argument, 0, 'R'},
{"ckdb-sockdir",required_argument, 0, 'S'}, {"ckdb-sockdir",required_argument, 0, 'S'},
{"sockdir", required_argument, 0, 's'}, {"sockdir", required_argument, 0, 's'},
{"trusted", no_argument, 0, 't'},
{"userproxy", no_argument, 0, 'u'}, {"userproxy", no_argument, 0, 'u'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
@ -1578,6 +1614,7 @@ static struct option long_options[] = {
{"proxy", no_argument, 0, 'p'}, {"proxy", no_argument, 0, 'p'},
{"redirector", no_argument, 0, 'R'}, {"redirector", no_argument, 0, 'R'},
{"sockdir", required_argument, 0, 's'}, {"sockdir", required_argument, 0, 's'},
{"trusted", no_argument, 0, 't'},
{"userproxy", no_argument, 0, 'u'}, {"userproxy", no_argument, 0, 'u'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
@ -1622,7 +1659,7 @@ int main(int argc, char **argv)
ckp.initial_args[ckp.args] = strdup(argv[ckp.args]); ckp.initial_args[ckp.args] = strdup(argv[ckp.args]);
ckp.initial_args[ckp.args] = NULL; ckp.initial_args[ckp.args] = NULL;
while ((c = getopt_long(argc, argv, "Ac:Dd:g:HhkLl:Nn:PpRS:s:u", long_options, &i)) != -1) { while ((c = getopt_long(argc, argv, "Ac:Dd:g:HhkLl:Nn:PpRS:s:tu", long_options, &i)) != -1) {
switch (c) { switch (c) {
case 'A': case 'A':
ckp.standalone = true; ckp.standalone = true;
@ -1702,6 +1739,11 @@ int main(int argc, char **argv)
case 's': case 's':
ckp.socket_dir = strdup(optarg); ckp.socket_dir = strdup(optarg);
break; break;
case 't':
if (ckp.proxy)
quit(1, "Cannot set a proxy type and trusted remote mode");
ckp.remote = true;
break;
case 'u': case 'u':
if (ckp.proxy || ckp.redirector || ckp.passthrough || ckp.node) if (ckp.proxy || ckp.redirector || ckp.passthrough || ckp.node)
quit(1, "Cannot set both userproxy and another proxy type or redirector"); quit(1, "Cannot set both userproxy and another proxy type or redirector");

5
src/ckpool.h

@ -180,6 +180,9 @@ struct ckpool_instance {
pthread_t pth_listener; pthread_t pth_listener;
pthread_t pth_watchdog; pthread_t pth_watchdog;
/* Are we running in trusted remote node mode */
bool remote;
/* Are we running in node proxy mode */ /* Are we running in node proxy mode */
bool node; bool node;
@ -227,6 +230,8 @@ struct ckpool_instance {
char **serverurl; // Array of URLs to bind our server/proxy to char **serverurl; // Array of URLs to bind our server/proxy to
int serverurls; // Number of server bindings int serverurls; // Number of server bindings
bool *nodeserver; // If this server URL serves node information bool *nodeserver; // If this server URL serves node information
bool *trusted; // If this server URL accepts trusted remote nodes
char *upstream; // Upstream pool in trusted remote mode
int update_interval; // Seconds between stratum updates int update_interval; // Seconds between stratum updates

Loading…
Cancel
Save