Add basic configuration options for redirector mode
This commit is contained in:
parent
f3a826d30f
commit
31c205c138
19
ckpassthrough.conf
Normal file
19
ckpassthrough.conf
Normal file
@ -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.
|
||||
@ -19,7 +19,6 @@
|
||||
"mindiff" : 1,
|
||||
"startdiff" : 42,
|
||||
"maxdiff" : 0,
|
||||
"clientsvspeed" : false,
|
||||
"logdir" : "logs"
|
||||
}
|
||||
Comments from here on are ignored.
|
||||
|
||||
22
ckredirector.conf
Normal file
22
ckredirector.conf
Normal file
@ -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
55
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";
|
||||
}
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user