From 3a9f5a491e494b744855a79e1d1ebee723d6fd71 Mon Sep 17 00:00:00 2001 From: ckolivas Date: Mon, 4 Jan 2016 09:14:08 +1100 Subject: [PATCH] Add an option to selectively enable/disable compression in passthrough modes --- README | 4 ++++ ckpassthrough.conf | 5 +---- src/ckpool.c | 4 ++++ src/ckpool.h | 3 +++ src/generator.c | 12 ++++++------ 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/README b/README index 8fd75b81..ee80ac62 100644 --- a/README +++ b/README @@ -265,6 +265,10 @@ new network blocks and is 100 by default. It is intended to be a backup only for when the notifier is not set up and only polls if the "notify" field is not set on a btcd. +"compress" : When running in a passthrough mode (redirector, passthrough, node), +should we gzip compress large packets. For passthroughs on a local network it +is recommended to disable this. Default is enabled. + "nonce1length" : This is optional allowing the extranonce1 length to be chosen from 2 to 8. Default 4 diff --git a/ckpassthrough.conf b/ckpassthrough.conf index a0c9a092..dc7b2ec1 100644 --- a/ckpassthrough.conf +++ b/ckpassthrough.conf @@ -6,14 +6,11 @@ "pass" : "pass" } ], -"update_interval" : 30, "serverurl" : [ "192.168.1.100:3334", "127.0.0.1:3334" ], -"mindiff" : 1, -"startdiff" : 42, -"maxdiff" : 0, +"compress" : true, "logdir" : "logs" } Comments from here on are ignored. diff --git a/src/ckpool.c b/src/ckpool.c index 00f9a908..3f8e4aab 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -1539,6 +1539,7 @@ static void parse_config(ckpool_t *ckp) ckp->btcsig[38] = '\0'; } json_get_int(&ckp->blockpoll, json_conf, "blockpoll"); + json_get_bool(&ckp->compress, json_conf, "compress"); json_get_int(&ckp->nonce1length, json_conf, "nonce1length"); json_get_int(&ckp->nonce2length, json_conf, "nonce2length"); json_get_int(&ckp->update_interval, json_conf, "update_interval"); @@ -1907,6 +1908,9 @@ int main(int argc, char **argv) if (ret && errno != EEXIST) quit(1, "Failed to make directory %s", ckp.socket_dir); + /* Set default on */ + ckp.compress = true; + parse_config(&ckp); /* Set defaults if not found in config file */ if (!ckp.btcds) { diff --git a/src/ckpool.h b/src/ckpool.h index 52017027..0ab30f4c 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -192,6 +192,9 @@ struct ckpool_instance { /* Are we a redirecting passthrough */ bool redirector; + /* Should we compress large packets in passthrough modes */ + bool compress; + /* Are we running as a proxy */ bool proxy; diff --git a/src/generator.c b/src/generator.c index 353dc641..49b0f215 100644 --- a/src/generator.c +++ b/src/generator.c @@ -766,7 +766,7 @@ out: } /* cs semaphore must be held */ -static bool passthrough_stratum(connsock_t *cs, proxy_instance_t *proxi) +static bool passthrough_stratum(ckpool_t *ckp, connsock_t *cs, proxy_instance_t *proxi) { json_t *req, *val = NULL, *res_val, *err_val; bool res, ret = false; @@ -774,7 +774,7 @@ static bool passthrough_stratum(connsock_t *cs, proxy_instance_t *proxi) JSON_CPACK(req, "{ss,sb,s[s]}", "method", "mining.passthrough", - "gz", json_true(), + "gz", ckp->compress, "params", PACKAGE"/"VERSION); res = send_json_msg(cs, req); json_decref(req); @@ -812,7 +812,7 @@ out: } /* cs semaphore must be held */ -static bool node_stratum(connsock_t *cs, proxy_instance_t *proxi) +static bool node_stratum(ckpool_t *ckp, connsock_t *cs, proxy_instance_t *proxi) { json_t *req, *val = NULL, *res_val, *err_val; bool res, ret = false; @@ -820,7 +820,7 @@ static bool node_stratum(connsock_t *cs, proxy_instance_t *proxi) JSON_CPACK(req, "{ss,sb,s[s]}", "method", "mining.node", - "gz", json_true(), + "gz", ckp->compress, "params", PACKAGE"/"VERSION); res = send_json_msg(cs, req); @@ -1855,7 +1855,7 @@ static bool proxy_alive(ckpool_t *ckp, proxy_instance_t *proxi, connsock_t *cs, goto out; } if (ckp->node) { - if (!node_stratum(cs, proxi)) { + if (!node_stratum(ckp, cs, proxi)) { LOGWARNING("Failed initial node setup to %s:%s !", cs->url, cs->port); goto out; @@ -1864,7 +1864,7 @@ static bool proxy_alive(ckpool_t *ckp, proxy_instance_t *proxi, connsock_t *cs, goto out; } if (ckp->passthrough) { - if (!passthrough_stratum(cs, proxi)) { + if (!passthrough_stratum(ckp, cs, proxi)) { LOGWARNING("Failed initial passthrough to %s:%s !", cs->url, cs->port); goto out;