From 1debfd1f45dcd3903c6e4a4d977de2db17aefc97 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 17 Jun 2014 00:12:31 +1000 Subject: [PATCH 1/3] Send auth and share messages to ckdb --- sql/initid.sh | 2 +- src/ckpool.c | 3 ++- src/ckpool.h | 4 ++-- src/stratifier.c | 39 ++++++++++++++++++++++++++++++++++----- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/sql/initid.sh b/sql/initid.sh index 78e01c11..d3dfe5af 100755 --- a/sql/initid.sh +++ b/sql/initid.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # fldsep="`echo -e '\x02'`" # diff --git a/src/ckpool.c b/src/ckpool.c index f8d801d1..5015dbc8 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -293,8 +293,9 @@ out: } /* As send_recv_proc but only to ckdb */ -char *_send_recv_ckdb(const char *path, const char *msg, const char *file, const char *func, const int line) +char *_send_recv_ckdb(const ckpool_t *ckp, const char *msg, const char *file, const char *func, const int line) { + const char *path = ckp->ckdb_sockname; char *buf = NULL; int sockd; diff --git a/src/ckpool.h b/src/ckpool.h index e7ce582c..3a857f37 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -134,8 +134,8 @@ bool _send_proc(proc_instance_t *pi, const char *msg, const char *file, const ch #define send_proc(pi, msg) _send_proc(pi, msg, __FILE__, __func__, __LINE__) char *_send_recv_proc(proc_instance_t *pi, const char *msg, const char *file, const char *func, const int line); #define send_recv_proc(pi, msg) _send_recv_proc(pi, msg, __FILE__, __func__, __LINE__) -char *_send_recv_ckdb(const char *path, const char *msg, const char *file, const char *func, const int line); -#define send_recv_ckdb(path, msg) _send_recv_ckdb(path, msg, __FILE__, __func__, __LINE__) +char *_send_recv_ckdb(const ckpool_t *ckp, const char *msg, const char *file, const char *func, const int line); +#define send_recv_ckdb(ckp, msg) _send_recv_ckdb(ckp, msg, __FILE__, __func__, __LINE__) json_t *json_rpc_call(connsock_t *cs, const char *rpc_req); diff --git a/src/stratifier.c b/src/stratifier.c index cd3d0eb3..15ea6559 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1178,10 +1178,11 @@ static user_instance_t *authorise_user(const char *workername) return instance; } -/* FIXME Send this to the database and parse the response to authorise a user - * and get paramters back */ +/* FIXME: Send this to the database and parse the response to authorise a user + * and get parameters back */ static bool send_recv_auth(stratum_instance_t *client) { + char *msg, *dump, *buf; char cdfield[64]; json_t *val; ts_t now; @@ -1200,8 +1201,17 @@ static bool send_recv_auth(stratum_instance_t *client) "createby", "code", "createcode", __func__, "createinet", "127.0.0.1"); -char *dump = json_dumps(val, 0); LOGDEBUG("id.authorise.json=%s",dump); dealloc(dump); + dump = json_dumps(val, 0); json_decref(val); + ASPRINTF(&msg, "id.authorise.json=%s", dump); + dealloc(dump); + buf = send_recv_ckdb(client->ckp, msg); + if (likely(buf)) { + LOGWARNING("Got auth response: %s", buf); + dealloc(buf); + } else + LOGWARNING("Got no auth response :("); + dealloc(msg); return true; } @@ -1531,6 +1541,7 @@ static json_t *parse_submit(stratum_instance_t *client, json_t *json_msg, const char *user, *job_id, *nonce2, *ntime, *nonce; double diff, wdiff = 0, sdiff = -1; enum share_err err = SE_NONE; + char *msg, *dump, *buf; char idstring[20]; uint32_t ntime32; char *fname, *s; @@ -1722,8 +1733,17 @@ out_unlock: } else LOGERR("Failed to fopen %s", fname); /* FIXME : Send val json to database here */ -s = json_dumps(val, 0); LOGDEBUG("id.sharelog.json=%s",s); dealloc(s); + dump = json_dumps(val, 0); json_decref(val); + ASPRINTF(&msg, "id.sharelog.json=%s", dump); + dealloc(dump); + buf = send_recv_ckdb(client->ckp, msg); + if (likely(buf)) { + LOGWARNING("Got sharelog response: %s", buf); + dealloc(buf); + } else + LOGWARNING("Got no sharelog response :("); + dealloc(msg); out: if (!share) { val = json_pack("{ss,si,ss,ss,si,ss,ss,so,si,ss,ss,ss,ss}", @@ -1741,8 +1761,17 @@ out: "createcode", __func__, "createinet", "127.0.0.1"); /* FIXME : Send val json to database here */ -s = json_dumps(val, 0); LOGDEBUG("id.sharelog.json=%s",s); dealloc(s); + dump = json_dumps(val, 0); json_decref(val); + ASPRINTF(&msg, "id.sharelog.json=%s", dump); + dealloc(dump); + buf = send_recv_ckdb(client->ckp, msg); + if (likely(buf)) { + LOGWARNING("Got sharelog response: %s", buf); + dealloc(buf); + } else + LOGWARNING("Got no sharelog response :("); + dealloc(msg); LOGINFO("Invalid share from client %d: %s", client->id, client->workername); } return json_boolean(result); From 83eb0821ed346e31d68d6d83c89eaafd98c2c680 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 17 Jun 2014 00:22:05 +1000 Subject: [PATCH 2/3] Send workinfo sharelog --- src/stratifier.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/stratifier.c b/src/stratifier.c index 15ea6559..57182c8e 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -401,6 +401,7 @@ static void purge_share_hashtable(int64_t wb_id) /* FIXME This message will be sent to the database once it's hooked in */ static void send_workinfo(ckpool_t *ckp, workbase_t *wb) { + char *msg, *dump, *buf; char cdfield[64]; json_t *val; @@ -423,8 +424,17 @@ static void send_workinfo(ckpool_t *ckp, workbase_t *wb) "createby", "code", "createcode", __func__, "createinet", "127.0.0.1"); -char *dump = json_dumps(val, 0); LOGDEBUG("id.sharelog.json=%s",dump); dealloc(dump); + dump = json_dumps(val, 0); json_decref(val); + ASPRINTF(&msg, "id.sharelog.json=%s", dump); + dealloc(dump); + buf = send_recv_ckdb(ckp, msg); + if (likely(buf)) { + LOGWARNING("Got workinfo response: %s", buf); + dealloc(buf); + } else + LOGWARNING("Got no workinfo response :("); + dealloc(msg); } static void add_base(ckpool_t *ckp, workbase_t *wb, bool *new_block) From 9111c4fdf9c010adf9bf2eda1132aa5526837e67 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 17 Jun 2014 00:23:33 +1000 Subject: [PATCH 3/3] Send stats to ckdb --- src/stratifier.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/stratifier.c b/src/stratifier.c index 57182c8e..eec5c487 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -2177,6 +2177,7 @@ static void *statsupdate(void *arg) const double nonces = 4294967296; double sps1, sps5, sps15, sps60; user_instance_t *instance, *tmp; + char *msg, *dump, *buf; int64_t pplns_shares; char fname[512] = {}; tv_t now, diff; @@ -2338,7 +2339,17 @@ static void *statsupdate(void *arg) "createby", "code", "createcode", __func__, "createinet", "127.0.0.1"); + dump = json_dumps(val, 0); json_decref(val); + ASPRINTF(&msg, "id.stats.json=%s", dump); + dealloc(dump); + buf = send_recv_ckdb(ckp, msg); + if (likely(buf)) { + LOGWARNING("Got stats response: %s", buf); + dealloc(buf); + } else + LOGWARNING("Got no stats response :("); + dealloc(msg); /* Update stats 4 times per minute for smooth values, displaying * status every minute. */