From fe94172f2e13df47e51040a86bf5de5645f7bc8d Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 2 Jan 2017 11:05:58 +1100 Subject: [PATCH] Strip remote field that won't be used or are recrated upstream. --- src/ckpool.h | 2 ++ src/connector.c | 10 ++++++++-- src/stratifier.c | 30 ++++++++++++++++++++++++------ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/ckpool.h b/src/ckpool.h index 7e95e2de..fc1fae5a 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -195,6 +195,8 @@ struct ckpool_instance { /* Are we running in trusted remote node mode */ bool remote; + /* Does our upstream pool in remote mode have ckdb */ + bool upstream_ckdb; /* Are we running in node proxy mode */ bool node; diff --git a/src/connector.c b/src/connector.c index c1cfcaa8..28ff5359 100644 --- a/src/connector.c +++ b/src/connector.c @@ -1048,7 +1048,7 @@ static void remote_server(ckpool_t *ckp, cdata_t *cdata, client_instance_t *clie LOGWARNING("Connector adding client %"PRId64" %s as remote trusted server", client->id, client->address_name); client->remote = true; - ASPRINTF(&buf, "{\"result\": true}\n"); + ASPRINTF(&buf, "{\"result\": true, \"ckdb\": %s}\n", CKP_STANDALONE(ckp) ? "false" : "true"); send_client(cdata, client->id, buf); if (!ckp->rmem_warn) set_recvbufsize(ckp, client->fd, 2097152); @@ -1100,7 +1100,13 @@ static bool connect_upstream(ckpool_t *ckp, connsock_t *cs) LOGWARNING("Denied upstream trusted connection"); goto out; } - LOGWARNING("Connected to upstream server %s:%s as trusted remote", cs->url, cs->port); + /* Parse whether the upstream pool is using ckdb or not. Default to yes + * if no ckdb field is received for backward compatibility. */ + res_val = json_object_get(val, "ckdb"); + if (!res_val || json_is_true(res_val)) + ckp->upstream_ckdb = true; + LOGWARNING("Connected to upstream %sckdb server %s:%s as trusted remote", + ckp->upstream_ckdb ? "" : "non-", cs->url, cs->port); ret = true; out: cksem_post(&cs->sem); diff --git a/src/stratifier.c b/src/stratifier.c index 9a616ee3..d68b4826 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -891,11 +891,26 @@ static void send_postponed(sdata_t *sdata) static void stratum_add_send(sdata_t *sdata, json_t *val, const int64_t client_id, const int msg_type); +/* Strip fields that will be recreated upstream or won't be used to minimise + * bandwidth. */ +static void strip_fields(ckpool_t *ckp, json_t *val) +{ + json_object_del(val, "poolinstance"); + json_object_del(val, "createby"); + if (!ckp->upstream_ckdb) { + json_object_del(val, "createdate"); + json_object_del(val, "createcode"); + json_object_del(val, "createinet"); + } +} + /* Send a json msg to an upstream trusted remote server */ -static void upstream_json(ckpool_t *ckp, const json_t *val) +static void upstream_json(ckpool_t *ckp, json_t *val) { - char *msg = json_dumps(val, JSON_NO_UTF8 | JSON_PRESERVE_ORDER | JSON_COMPACT | JSON_EOL); + char *msg; + strip_fields(ckp, val); + msg = json_dumps(val, JSON_NO_UTF8 | JSON_PRESERVE_ORDER | JSON_COMPACT | JSON_EOL); /* Connector absorbs and frees msg */ connector_upstream_msg(ckp, msg); } @@ -5937,7 +5952,7 @@ out: json_set_string(val, "createby", "code"); json_set_string(val, "createcode", __func__); json_set_string(val, "createinet", ckp->serverurl[client->server]); - if (ckp->remote) + if (ckp->remote && ckp->upstream_ckdb) upstream_json_msgtype(ckp, val, SM_SHAREERR); else ckdbq_add(ckp, ID_SHAREERR, val); @@ -6802,8 +6817,11 @@ static void parse_trusted_msg(ckpool_t *ckp, sdata_t *sdata, json_t *val, stratu LOGWARNING("Failed to get method from remote message %s", buf); goto out; } - /* Rename the pool instance to match main pool (for now?) */ - json_set_string(val, "poolinstance", ckp->name); + if (!CKP_STANDALONE(ckp)) { + /* Rename the pool instance to match main pool (for now?) */ + json_set_string(val, "poolinstance", ckp->name); + json_set_string(val, "createby", "remote"); + } if (likely(!safecmp(method, stratum_msgs[SM_SHARE]))) parse_remote_share(ckp, sdata, val, buf); @@ -7504,7 +7522,7 @@ static void update_workerstats(ckpool_t *ckp, sdata_t *sdata) /* Add all entries outside of the instance lock */ DL_FOREACH_SAFE(json_list, entry, tmpentry) { - if (ckp->remote) + if (ckp->remote && ckp->upstream_ckdb) upstream_json_msgtype(ckp, entry->val, SM_WORKERSTATS); else ckdbq_add(ckp, ID_WORKERSTATS, entry->val);