Browse Source

Privatise all global variables within the generator to allow multiple ckpools in the future

master
Con Kolivas 10 years ago
parent
commit
fe15f9384d
  1. 3
      src/ckpool.h
  2. 23
      src/generator.c

3
src/ckpool.h

@ -172,6 +172,9 @@ struct ckpool_instance {
char **proxyauth; char **proxyauth;
char **proxypass; char **proxypass;
server_instance_t *btcdbackup; server_instance_t *btcdbackup;
/* Private data for each process */
void *data;
}; };
#ifdef USE_CKDB #ifdef USE_CKDB

23
src/generator.c

@ -122,9 +122,13 @@ struct proxy_instance {
typedef struct proxy_instance proxy_instance_t; typedef struct proxy_instance proxy_instance_t;
static int proxy_notify_id; // Globally increasing notify id /* Private data for the generator */
struct generator_data {
int proxy_notify_id; // Globally increasing notify id
ckmsgq_t *srvchk; // Server check message queue
};
static ckmsgq_t *srvchk; // Server check message queue typedef struct generator_data gdata_t;
static bool server_alive(ckpool_t *ckp, server_instance_t *si, bool pinging) static bool server_alive(ckpool_t *ckp, server_instance_t *si, bool pinging)
{ {
@ -238,6 +242,7 @@ static int gen_loop(proc_instance_t *pi)
bool reconnecting = false; bool reconnecting = false;
unixsock_t *us = &pi->us; unixsock_t *us = &pi->us;
ckpool_t *ckp = pi->ckp; ckpool_t *ckp = pi->ckp;
gdata_t *gdata = ckp->data;
bool started = false; bool started = false;
char *buf = NULL; char *buf = NULL;
connsock_t *cs; connsock_t *cs;
@ -261,7 +266,7 @@ reconnect:
} }
retry: retry:
ckmsgq_add(srvchk, si); ckmsgq_add(gdata->srvchk, si);
do { do {
selret = wait_read_select(us->sockd, 5); selret = wait_read_select(us->sockd, 5);
@ -681,6 +686,7 @@ static bool parse_notify(proxy_instance_t *proxi, json_t *val)
{ {
const char *prev_hash, *bbversion, *nbit, *ntime; const char *prev_hash, *bbversion, *nbit, *ntime;
char *job_id, *coinbase1, *coinbase2; char *job_id, *coinbase1, *coinbase2;
gdata_t *gdata = proxi->ckp->data;
bool clean, ret = false; bool clean, ret = false;
notify_instance_t *ni; notify_instance_t *ni;
int merkles, i; int merkles, i;
@ -740,7 +746,7 @@ static bool parse_notify(proxy_instance_t *proxi, json_t *val)
ni->notify_time = time(NULL); ni->notify_time = time(NULL);
mutex_lock(&proxi->notify_lock); mutex_lock(&proxi->notify_lock);
ni->id = proxy_notify_id++; ni->id = gdata->proxy_notify_id++;
HASH_ADD_INT(proxi->notify_instances, id, ni); HASH_ADD_INT(proxi->notify_instances, id, ni);
proxi->current_notify = ni; proxi->current_notify = ni;
mutex_unlock(&proxi->notify_lock); mutex_unlock(&proxi->notify_lock);
@ -1448,6 +1454,7 @@ static int proxy_loop(proc_instance_t *pi)
bool reconnecting = false; bool reconnecting = false;
unixsock_t *us = &pi->us; unixsock_t *us = &pi->us;
ckpool_t *ckp = pi->ckp; ckpool_t *ckp = pi->ckp;
gdata_t *gdata = ckp->data;
char *buf = NULL; char *buf = NULL;
reconnect: reconnect:
@ -1474,7 +1481,7 @@ reconnect:
} }
retry: retry:
ckmsgq_add(srvchk, proxi->si); ckmsgq_add(gdata->srvchk, proxi->si);
do { do {
selret = wait_read_select(us->sockd, 5); selret = wait_read_select(us->sockd, 5);
@ -1725,11 +1732,13 @@ static void server_watchdog(ckpool_t *ckp, server_instance_t *cursi)
int generator(proc_instance_t *pi) int generator(proc_instance_t *pi)
{ {
ckpool_t *ckp = pi->ckp; ckpool_t *ckp = pi->ckp;
gdata_t *gdata;
int ret; int ret;
LOGWARNING("%s generator starting", ckp->name); LOGWARNING("%s generator starting", ckp->name);
gdata = ckzalloc(sizeof(gdata_t));
srvchk = create_ckmsgq(ckp, "srvchk", &server_watchdog); ckp->data = gdata;
gdata->srvchk = create_ckmsgq(ckp, "srvchk", &server_watchdog);
if (ckp->proxy) if (ckp->proxy)
ret = proxy_mode(ckp, pi); ret = proxy_mode(ckp, pi);

Loading…
Cancel
Save