Browse Source

Call the generator directly from the stratifier for getbest calls instead of via messaging.

master
Con Kolivas 8 years ago
parent
commit
6af2c10103
  1. 31
      src/generator.c
  2. 5
      src/generator.h
  3. 39
      src/stratifier.c

31
src/generator.c

@ -827,6 +827,37 @@ out:
return val; return val;
} }
int generator_getbest(ckpool_t *ckp, char *hash)
{
gdata_t *gdata = ckp->gdata;
int ret = GETBEST_FAILED;
server_instance_t *si;
connsock_t *cs;
/* Use temporary variables to prevent deref while accessing */
si = gdata->current_si;
if (unlikely(!si)) {
LOGWARNING("No live current server in generator_getbest");
goto out;
}
if (si->notify) {
ret = GETBEST_NOTIFY;
goto out;
}
cs = &si->cs;
if (unlikely(!cs)) {
LOGWARNING("No live connsock for current server in generator_getbest");
goto out;
}
if (unlikely(!get_bestblockhash(cs, hash))) {
LOGWARNING("Failed to get best block hash from %s:%s", cs->url, cs->port);
goto out;
}
ret = GETBEST_SUCCESS;
out:
return ret;
}
static bool parse_notify(ckpool_t *ckp, proxy_instance_t *proxi, json_t *val) static bool parse_notify(ckpool_t *ckp, proxy_instance_t *proxi, json_t *val)
{ {
const char *prev_hash, *bbversion, *nbit, *ntime; const char *prev_hash, *bbversion, *nbit, *ntime;

5
src/generator.h

@ -12,8 +12,13 @@
#include "config.h" #include "config.h"
#define GETBEST_FAILED -1
#define GETBEST_NOTIFY 0
#define GETBEST_SUCCESS 1
void generator_add_send(ckpool_t *ckp, json_t *val); void generator_add_send(ckpool_t *ckp, json_t *val);
json_t *generator_genbase(ckpool_t *ckp); json_t *generator_genbase(ckpool_t *ckp);
int generator_getbest(ckpool_t *ckp, char *hash);
void *generator(void *arg); void *generator(void *arg);
#endif /* GENERATOR_H */ #endif /* GENERATOR_H */

39
src/stratifier.c

@ -1143,19 +1143,6 @@ static char *__send_recv_generator(ckpool_t *ckp, const char *msg, const int pri
return buf; return buf;
} }
/* Conditionally send_recv a message only if it's equal or higher priority than
* any currently being serviced. NULL is returned if the request is not
* processed for priority reasons, "failed" for an actual failure. */
static char *send_recv_generator(ckpool_t *ckp, const char *msg, const int prio)
{
sdata_t *sdata = ckp->sdata;
char *buf = NULL;
if (prio >= sdata->gen_priority)
buf = __send_recv_generator(ckp, msg, prio);
return buf;
}
static void send_generator(ckpool_t *ckp, const char *msg, const int prio) static void send_generator(ckpool_t *ckp, const char *msg, const int prio)
{ {
sdata_t *sdata = ckp->sdata; sdata_t *sdata = ckp->sdata;
@ -4390,27 +4377,29 @@ static void *blockupdate(void *arg)
{ {
ckpool_t *ckp = (ckpool_t *)arg; ckpool_t *ckp = (ckpool_t *)arg;
sdata_t *sdata = ckp->sdata; sdata_t *sdata = ckp->sdata;
char *buf = NULL; char hash[68];
char request[8];
pthread_detach(pthread_self()); pthread_detach(pthread_self());
rename_proc("blockupdate"); rename_proc("blockupdate");
buf = send_recv_proc(ckp->generator, "getbest");
if (!cmdmatch(buf, "failed"))
sprintf(request, "getbest");
else
sprintf(request, "getlast");
while (42) { while (42) {
dealloc(buf); int ret;
buf = send_recv_generator(ckp, request, GEN_LAX);
if (buf && cmdmatch(buf, "notify")) ret = generator_getbest(ckp, hash);
switch (ret) {
case GETBEST_NOTIFY:
cksleep_ms(5000); cksleep_ms(5000);
else if (buf && strcmp(buf, sdata->lastswaphash) && !cmdmatch(buf, "failed")) break;
case GETBEST_SUCCESS:
if (strcmp(hash, sdata->lastswaphash)) {
update_base(sdata, GEN_PRIORITY); update_base(sdata, GEN_PRIORITY);
else break;
}
case GETBEST_FAILED:
default:
cksleep_ms(ckp->blockpoll); cksleep_ms(ckp->blockpoll);
} }
}
return NULL; return NULL;
} }

Loading…
Cancel
Save