diff --git a/src/Makefile.am b/src/Makefile.am index 61d13a6d..de543330 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,7 +10,7 @@ libckpool_la_LIBADD = @PTHREAD_LIBS@ @MATH_LIBS@ @RT_LIBS@ bin_PROGRAMS = ckpool ckpmsg notifier ckpool_SOURCES = ckpool.c ckpool.h generator.c generator.h bitcoin.c bitcoin.h \ stratifier.c stratifier.h connector.c connector.h uthash.h \ - utlist.h + utlist.h api.c api.h ckpool_LDADD = libckpool.la @JANSSON_LIBS@ ckpmsg_SOURCES = ckpmsg.c diff --git a/src/ckpool.c b/src/ckpool.c index 21f3da4b..8b45df8b 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -31,6 +31,7 @@ #include "generator.h" #include "stratifier.h" #include "connector.h" +#include "api.h" ckpool_t *global_ckp; @@ -294,6 +295,17 @@ out: return ret; } +static void api_message(ckpool_t *ckp, char **buf, int *sockd) +{ + apimsg_t *apimsg = ckalloc(sizeof(apimsg_t)); + + apimsg->buf = *buf; + *buf = NULL; + apimsg->sockd = *sockd; + *sockd = -1; + ckmsgq_add(ckp->ckpapi, apimsg); +} + /* Listen for incoming global requests. Always returns a response if possible */ static void *listener(void *arg) { @@ -316,6 +328,9 @@ retry: if (!buf) { LOGWARNING("Failed to get message in listener"); send_unix_msg(sockd, "failed"); + } else if (buf[0] == '{') { + /* Any JSON messages received are for the RPC API to handle */ + api_message(ckp, &buf, &sockd); } else if (cmdmatch(buf, "shutdown")) { LOGWARNING("Listener received shutdown message, terminating ckpool"); send_unix_msg(sockd, "exiting"); @@ -1684,6 +1699,7 @@ int main(int argc, char **argv) launch_logger(&ckp.main); ckp.logfd = fileno(ckp.logfp); + ckp.ckpapi = create_ckmsgq(&ckp, "api", &ckpool_api); create_pthread(&ckp.pth_listener, listener, &ckp.main); /* Launch separate processes from here */ diff --git a/src/ckpool.h b/src/ckpool.h index 64abe7b8..e9bc4793 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -135,6 +135,9 @@ struct ckpool_instance { /* How many clients maximum to accept before rejecting further */ int maxclients; + /* API message queue */ + ckmsgq_t *ckpapi; + /* Logger message queue NOTE: Unique per process */ ckmsgq_t *logger; /* Process instance data of parent/child processes */