Browse Source

Remove unnecessary use of gbt as private data in socket instance.

master
Con Kolivas 8 years ago
parent
commit
e0d3a7df60
  1. 2
      src/ckpool.h
  2. 18
      src/generator.c

2
src/ckpool.h

@ -122,8 +122,6 @@ struct server_instance {
bool notify; bool notify;
bool alive; bool alive;
connsock_t cs; connsock_t cs;
void *data; // Private data
}; };
typedef struct server_instance server_instance_t; typedef struct server_instance server_instance_t;

18
src/generator.c

@ -194,7 +194,7 @@ static bool server_alive(ckpool_t *ckp, server_instance_t *si, bool pinging)
char *userpass = NULL; char *userpass = NULL;
bool ret = false; bool ret = false;
connsock_t *cs; connsock_t *cs;
gbtbase_t *gbt; gbtbase_t gbt;
int fd; int fd;
if (si->alive) if (si->alive)
@ -222,16 +222,14 @@ static bool server_alive(ckpool_t *ckp, server_instance_t *si, bool pinging)
} }
/* Test we can connect, authorise and get a block template */ /* Test we can connect, authorise and get a block template */
gbt = ckzalloc(sizeof(gbtbase_t)); if (!gen_gbtbase(cs, &gbt)) {
si->data = gbt;
if (!gen_gbtbase(cs, gbt)) {
if (!pinging) { if (!pinging) {
LOGINFO("Failed to get test block template from %s:%s!", LOGINFO("Failed to get test block template from %s:%s!",
cs->url, cs->port); cs->url, cs->port);
} }
goto out; goto out;
} }
clear_gbtbase(gbt); clear_gbtbase(&gbt);
if (!ckp->node && !validate_address(cs, ckp->btcaddress)) { if (!ckp->node && !validate_address(cs, ckp->btcaddress)) {
LOGWARNING("Invalid btcaddress: %s !", ckp->btcaddress); LOGWARNING("Invalid btcaddress: %s !", ckp->btcaddress);
goto out; goto out;
@ -299,7 +297,6 @@ static void kill_server(server_instance_t *si)
dealloc(cs->url); dealloc(cs->url);
dealloc(cs->port); dealloc(cs->port);
dealloc(cs->auth); dealloc(cs->auth);
dealloc(si->data);
} }
static void clear_unix_msg(unix_msg_t **umsg) static void clear_unix_msg(unix_msg_t **umsg)
@ -365,7 +362,7 @@ static void gen_loop(proc_instance_t *pi)
ckpool_t *ckp = pi->ckp; ckpool_t *ckp = pi->ckp;
char *buf = NULL; char *buf = NULL;
connsock_t *cs; connsock_t *cs;
gbtbase_t *gbt; gbtbase_t gbt;
char hash[68]; char hash[68];
reconnect: reconnect:
@ -379,7 +376,6 @@ reconnect:
LOGWARNING("%s generator ready", ckp->name); LOGWARNING("%s generator ready", ckp->name);
} }
gbt = si->data;
cs = &si->cs; cs = &si->cs;
if (!old_si) if (!old_si)
LOGWARNING("Connected to bitcoind: %s:%s", cs->url, cs->port); LOGWARNING("Connected to bitcoind: %s:%s", cs->url, cs->port);
@ -401,18 +397,18 @@ retry:
buf = umsg->buf; buf = umsg->buf;
LOGDEBUG("Generator received request: %s", buf); LOGDEBUG("Generator received request: %s", buf);
if (cmdmatch(buf, "getbase")) { if (cmdmatch(buf, "getbase")) {
if (!gen_gbtbase(cs, gbt)) { if (!gen_gbtbase(cs, &gbt)) {
LOGWARNING("Failed to get block template from %s:%s", LOGWARNING("Failed to get block template from %s:%s",
cs->url, cs->port); cs->url, cs->port);
si->alive = cs->alive = false; si->alive = cs->alive = false;
send_unix_msg(umsg->sockd, "Failed"); send_unix_msg(umsg->sockd, "Failed");
goto reconnect; goto reconnect;
} else { } else {
char *s = json_dumps(gbt->json, JSON_NO_UTF8); char *s = json_dumps(gbt.json, JSON_NO_UTF8);
send_unix_msg(umsg->sockd, s); send_unix_msg(umsg->sockd, s);
free(s); free(s);
clear_gbtbase(gbt); clear_gbtbase(&gbt);
} }
} else if (cmdmatch(buf, "getbest")) { } else if (cmdmatch(buf, "getbest")) {
if (si->notify) if (si->notify)

Loading…
Cancel
Save