From 31c205c138cd3dd42a75f2b148606e180e8ee6c2 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 11 Jun 2015 12:05:01 +1000 Subject: [PATCH] Add basic configuration options for redirector mode --- ckpassthrough.conf | 19 ++++++++++++++++ ckproxy.conf | 1 - ckredirector.conf | 22 +++++++++++++++++++ src/ckpool.c | 55 +++++++++++++++++++++++++++++++++++++++++----- src/ckpool.h | 7 ++++++ 5 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 ckpassthrough.conf create mode 100644 ckredirector.conf diff --git a/ckpassthrough.conf b/ckpassthrough.conf new file mode 100644 index 00000000..a0c9a092 --- /dev/null +++ b/ckpassthrough.conf @@ -0,0 +1,19 @@ +{ +"proxy" : [ + { + "url" : "ckpool.org:3333", + "auth" : "user", + "pass" : "pass" + } +], +"update_interval" : 30, +"serverurl" : [ + "192.168.1.100:3334", + "127.0.0.1:3334" + ], +"mindiff" : 1, +"startdiff" : 42, +"maxdiff" : 0, +"logdir" : "logs" +} +Comments from here on are ignored. diff --git a/ckproxy.conf b/ckproxy.conf index 5daddb5b..fec5783a 100644 --- a/ckproxy.conf +++ b/ckproxy.conf @@ -19,7 +19,6 @@ "mindiff" : 1, "startdiff" : 42, "maxdiff" : 0, -"clientsvspeed" : false, "logdir" : "logs" } Comments from here on are ignored. diff --git a/ckredirector.conf b/ckredirector.conf new file mode 100644 index 00000000..1a0f8733 --- /dev/null +++ b/ckredirector.conf @@ -0,0 +1,22 @@ +{ +"proxy" : [ + { + "url" : "ckpool.org:3333", + "auth" : "user", + "pass" : "pass" + } +], +"update_interval" : 30, +"serverurl" : [ + "192.168.1.100:3334", + "127.0.0.1:3334" + ], +"redirecturl" : [ + "node.ckpool.org:3333" + ], +"mindiff" : 1, +"startdiff" : 42, +"maxdiff" : 0, +"logdir" : "logs" +} +Comments from here on are ignored. diff --git a/src/ckpool.c b/src/ckpool.c index c4537d50..044e6cb9 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -1258,6 +1258,36 @@ out: return ret; } +static bool parse_redirecturls(ckpool_t *ckp, const json_t *arr_val) +{ + bool ret = false; + int arr_size, i; + + if (!arr_val) + goto out; + if (!json_is_array(arr_val)) { + LOGNOTICE("Unable to parse redirecturl entries as an array"); + goto out; + } + arr_size = json_array_size(arr_val); + if (!arr_size) { + LOGWARNING("redirecturl array empty"); + goto out; + } + ckp->redirecturls = arr_size; + ckp->redirecturl = 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->redirecturl[i], val, "redirecturl")) + LOGWARNING("Invalid redirecturl entry number %d", i); + } + ret = true; +out: + return ret; +} + + static void parse_config(ckpool_t *ckp) { json_t *json_conf, *arr_val; @@ -1307,6 +1337,10 @@ static void parse_config(ckpool_t *ckp) if (arr_size) parse_proxies(ckp, arr_val, arr_size); } + arr_val = json_object_get(json_conf, "redirecturl"); + if (arr_val) + parse_redirecturls(ckp, arr_val); + json_decref(json_conf); } @@ -1434,6 +1468,7 @@ static struct option long_options[] = { {"name", required_argument, 0, 'n'}, {"passthrough", no_argument, 0, 'P'}, {"proxy", no_argument, 0, 'p'}, + {"redirector", no_argument, 0, 'R'}, {"ckdb-sockdir",required_argument, 0, 'S'}, {"sockdir", required_argument, 0, 's'}, {0, 0, 0, 0} @@ -1451,6 +1486,7 @@ static struct option long_options[] = { {"name", required_argument, 0, 'n'}, {"passthrough", no_argument, 0, 'P'}, {"proxy", no_argument, 0, 'p'}, + {"redirector", no_argument, 0, 'R'}, {"sockdir", required_argument, 0, 's'}, {0, 0, 0, 0} }; @@ -1494,7 +1530,7 @@ int main(int argc, char **argv) ckp.initial_args[ckp.args] = strdup(argv[ckp.args]); ckp.initial_args[ckp.args] = NULL; - while ((c = getopt_long(argc, argv, "Ac:Dd:g:HhkLl:n:PpS:s:", long_options, &i)) != -1) { + while ((c = getopt_long(argc, argv, "Ac:Dd:g:HhkLl:n:PpRS:s:", long_options, &i)) != -1) { switch (c) { case 'A': ckp.standalone = true; @@ -1549,15 +1585,20 @@ int main(int argc, char **argv) ckp.name = optarg; break; case 'P': - if (ckp.proxy) - quit(1, "Cannot set both proxy and passthrough mode"); + if (ckp.proxy || ckp.redirector) + quit(1, "Cannot set both proxy or redirector and passthrough mode"); ckp.standalone = ckp.proxy = ckp.passthrough = true; break; case 'p': - if (ckp.passthrough) - quit(1, "Cannot set both passthrough and proxy mode"); + if (ckp.passthrough || ckp.redirector) + quit(1, "Cannot set both passthrough or redirector and proxy mode"); ckp.proxy = true; break; + case 'R': + if (ckp.proxy || ckp.passthrough) + quit(1, "Cannot set both proxy or passthrough and redirector modes"); + ckp.standalone = ckp.proxy = ckp.passthrough = ckp.redirector = true; + break; case 'S': ckp.ckdb_sockdir = strdup(optarg); break; @@ -1570,6 +1611,10 @@ int main(int argc, char **argv) if (!ckp.name) { if (ckp.proxy) ckp.name = "ckproxy"; + else if (ckp.redirector) + ckp.name = "ckredirector"; + else if (ckp.passthrough) + ckp.name = "ckpassthrough"; else ckp.name = "ckpool"; } diff --git a/src/ckpool.h b/src/ckpool.h index 5fbaed5b..010a4db5 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -177,6 +177,9 @@ struct ckpool_instance { /* Are we running in passthrough mode */ bool passthrough; + /* Are we a redirecting passthrough */ + bool redirector; + /* Are we running as a proxy */ bool proxy; @@ -219,6 +222,10 @@ struct ckpool_instance { char **proxyauth; char **proxypass; + /* Passthrough redirect options */ + int redirecturls; + char **redirecturl; + /* Private data for each process */ void *data; };