Browse Source

Add basic configuration options for redirector mode

master
Con Kolivas 10 years ago
parent
commit
31c205c138
  1. 19
      ckpassthrough.conf
  2. 1
      ckproxy.conf
  3. 22
      ckredirector.conf
  4. 55
      src/ckpool.c
  5. 7
      src/ckpool.h

19
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.

1
ckproxy.conf

@ -19,7 +19,6 @@
"mindiff" : 1, "mindiff" : 1,
"startdiff" : 42, "startdiff" : 42,
"maxdiff" : 0, "maxdiff" : 0,
"clientsvspeed" : false,
"logdir" : "logs" "logdir" : "logs"
} }
Comments from here on are ignored. Comments from here on are ignored.

22
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.

55
src/ckpool.c

@ -1258,6 +1258,36 @@ out:
return ret; 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) static void parse_config(ckpool_t *ckp)
{ {
json_t *json_conf, *arr_val; json_t *json_conf, *arr_val;
@ -1307,6 +1337,10 @@ static void parse_config(ckpool_t *ckp)
if (arr_size) if (arr_size)
parse_proxies(ckp, arr_val, 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); json_decref(json_conf);
} }
@ -1434,6 +1468,7 @@ static struct option long_options[] = {
{"name", required_argument, 0, 'n'}, {"name", required_argument, 0, 'n'},
{"passthrough", no_argument, 0, 'P'}, {"passthrough", no_argument, 0, 'P'},
{"proxy", no_argument, 0, 'p'}, {"proxy", no_argument, 0, 'p'},
{"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'},
{0, 0, 0, 0} {0, 0, 0, 0}
@ -1451,6 +1486,7 @@ static struct option long_options[] = {
{"name", required_argument, 0, 'n'}, {"name", required_argument, 0, 'n'},
{"passthrough", no_argument, 0, 'P'}, {"passthrough", no_argument, 0, 'P'},
{"proxy", no_argument, 0, 'p'}, {"proxy", no_argument, 0, 'p'},
{"redirector", no_argument, 0, 'R'},
{"sockdir", required_argument, 0, 's'}, {"sockdir", required_argument, 0, 's'},
{0, 0, 0, 0} {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] = 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: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) { switch (c) {
case 'A': case 'A':
ckp.standalone = true; ckp.standalone = true;
@ -1549,15 +1585,20 @@ int main(int argc, char **argv)
ckp.name = optarg; ckp.name = optarg;
break; break;
case 'P': case 'P':
if (ckp.proxy) if (ckp.proxy || ckp.redirector)
quit(1, "Cannot set both proxy and passthrough mode"); quit(1, "Cannot set both proxy or redirector and passthrough mode");
ckp.standalone = ckp.proxy = ckp.passthrough = true; ckp.standalone = ckp.proxy = ckp.passthrough = true;
break; break;
case 'p': case 'p':
if (ckp.passthrough) if (ckp.passthrough || ckp.redirector)
quit(1, "Cannot set both passthrough and proxy mode"); quit(1, "Cannot set both passthrough or redirector and proxy mode");
ckp.proxy = true; ckp.proxy = true;
break; 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': case 'S':
ckp.ckdb_sockdir = strdup(optarg); ckp.ckdb_sockdir = strdup(optarg);
break; break;
@ -1570,6 +1611,10 @@ int main(int argc, char **argv)
if (!ckp.name) { if (!ckp.name) {
if (ckp.proxy) if (ckp.proxy)
ckp.name = "ckproxy"; ckp.name = "ckproxy";
else if (ckp.redirector)
ckp.name = "ckredirector";
else if (ckp.passthrough)
ckp.name = "ckpassthrough";
else else
ckp.name = "ckpool"; ckp.name = "ckpool";
} }

7
src/ckpool.h

@ -177,6 +177,9 @@ struct ckpool_instance {
/* Are we running in passthrough mode */ /* Are we running in passthrough mode */
bool passthrough; bool passthrough;
/* Are we a redirecting passthrough */
bool redirector;
/* Are we running as a proxy */ /* Are we running as a proxy */
bool proxy; bool proxy;
@ -219,6 +222,10 @@ struct ckpool_instance {
char **proxyauth; char **proxyauth;
char **proxypass; char **proxypass;
/* Passthrough redirect options */
int redirecturls;
char **redirecturl;
/* Private data for each process */ /* Private data for each process */
void *data; void *data;
}; };

Loading…
Cancel
Save