Browse Source

Add and test a getbase function of the generator process

master
Con Kolivas 11 years ago
parent
commit
945c730447
  1. 13
      src/ckpool.c
  2. 24
      src/generator.c
  3. 3
      src/libckpool.c

13
src/ckpool.c

@ -196,16 +196,25 @@ static void parse_config(ckpool_t *ckp)
static void test_functions(ckpool_t *ckp) static void test_functions(ckpool_t *ckp)
{ {
char *path = ckp->generator.us.path; char *path = ckp->generator.us.path, *buf;
int genfd; int genfd;
genfd = open_unix_client(ckp->generator.us.path);
if (genfd < 0) {
LOGWARNING("Failed to open generator socket %s", path);
return;
}
send_unix_msg(genfd, "getbase");
buf = recv_unix_msg(genfd);
LOGWARNING("getbase response: %s", buf);
dealloc(buf);
genfd = open_unix_client(ckp->generator.us.path); genfd = open_unix_client(ckp->generator.us.path);
if (genfd < 0) { if (genfd < 0) {
LOGWARNING("Failed to open generator socket %s", path); LOGWARNING("Failed to open generator socket %s", path);
return; return;
} }
send_unix_msg(genfd, "shutdown"); send_unix_msg(genfd, "shutdown");
close(genfd);
} }
int main(int argc, char **argv) int main(int argc, char **argv)

24
src/generator.c

@ -18,12 +18,12 @@
#include "generator.h" #include "generator.h"
#include "bitcoin.h" #include "bitcoin.h"
static int gen_loop(proc_instance_t *pi) static int gen_loop(proc_instance_t *pi, connsock_t *cs)
{ {
unixsock_t *us = &pi->us; unixsock_t *us = &pi->us;
int sockd, ret = 0; int sockd, ret = 0;
char *buf = NULL;
gbtbase_t gbt; gbtbase_t gbt;
char *buf;
memset(&gbt, 0, sizeof(gbt)); memset(&gbt, 0, sizeof(gbt));
retry: retry:
@ -36,6 +36,7 @@ retry:
goto out; goto out;
} }
dealloc(buf);
buf = recv_unix_msg(sockd); buf = recv_unix_msg(sockd);
if (!buf) { if (!buf) {
LOGWARNING("Failed to get message in gen_loop"); LOGWARNING("Failed to get message in gen_loop");
@ -43,13 +44,26 @@ retry:
goto retry; goto retry;
} }
LOGDEBUG("Generator received request: %s", buf); LOGDEBUG("Generator received request: %s", buf);
if (!strncmp(buf, "shutdown", 8)) if (!strncasecmp(buf, "shutdown", 8))
goto out; goto out;
dealloc(buf); if (!strncasecmp(buf, "getbase", 7)) {
if (!gen_gbtbase(cs, &gbt)) {
LOGWARNING("Failed to get block template from %s:%s",
cs->url, cs->port);
send_unix_msg(sockd, "Failed");
} else {
char *s = json_dumps(gbt.json, 0);
send_unix_msg(sockd, s);
free(s);
clear_gbtbase(&gbt);
}
}
close(sockd); close(sockd);
goto retry; goto retry;
out: out:
dealloc(buf);
return ret; return ret;
} }
@ -102,7 +116,7 @@ int generator(proc_instance_t *pi)
} }
clear_gbtbase(&gbt); clear_gbtbase(&gbt);
ret = gen_loop(pi); ret = gen_loop(pi, &cs);
out: out:
/* Clean up here */ /* Clean up here */
dealloc(cs.url); dealloc(cs.url);

3
src/libckpool.c

@ -649,7 +649,8 @@ char *recv_unix_msg(int sockd)
LOGWARNING("Invalid message length zero sent to recv_unix_msg"); LOGWARNING("Invalid message length zero sent to recv_unix_msg");
goto out; goto out;
} }
buf = ckalloc(msglen); buf = ckalloc(msglen + 1);
buf[msglen] = 0;
ofs = 0; ofs = 0;
while (msglen) { while (msglen) {
ret = read(sockd, buf + ofs, msglen); ret = read(sockd, buf + ofs, msglen);

Loading…
Cancel
Save