kanoi 10 years ago
parent
commit
8ba9a6abac
  1. 8
      src/ckpool.c
  2. 19
      src/connector.c
  3. 17
      src/generator.c
  4. 33
      src/stratifier.c

8
src/ckpool.c

@ -195,14 +195,14 @@ retry:
if (!buf) {
LOGWARNING("Failed to get message in listener");
send_unix_msg(sockd, "failed");
} else if (!strncasecmp(buf, "shutdown", 8)) {
} else if (cmdmatch(buf, "shutdown")) {
LOGWARNING("Listener received shutdown message, terminating ckpool");
send_unix_msg(sockd, "exiting");
goto out;
} else if (!strncasecmp(buf, "ping", 4)) {
} else if (cmdmatch(buf, "ping")) {
LOGDEBUG("Listener received ping request");
send_unix_msg(sockd, "pong");
} else if (!strncasecmp(buf, "loglevel", 8)) {
} else if (cmdmatch(buf, "loglevel")) {
int loglevel;
if (sscanf(buf, "loglevel=%d", &loglevel) != 1) {
@ -216,7 +216,7 @@ retry:
broadcast_proc(ckp, buf);
send_unix_msg(sockd, "success");
}
} else if (!strncasecmp(buf, "getfd", 5)) {
} else if (cmdmatch(buf, "getfd")) {
char *msg;
msg = send_recv_proc(ckp->connector, "getfd");

19
src/connector.c

@ -499,6 +499,9 @@ static int connector_loop(proc_instance_t *pi, conn_instance_t *ci)
goto out;
}
} while (selret < 1);
LOGWARNING("%s connector ready", ckp->name);
retry:
close(sockd);
sockd = accept(us->sockd, NULL, NULL);
@ -514,30 +517,30 @@ retry:
LOGWARNING("Failed to get message in connector_loop");
goto retry;
}
if (!strncasecmp(buf, "ping", 4)) {
if (cmdmatch(buf, "ping")) {
LOGDEBUG("Connector received ping request");
send_unix_msg(sockd, "pong");
goto retry;
}
if (!strncasecmp(buf, "accept", 6)) {
if (cmdmatch(buf, "accept")) {
LOGDEBUG("Connector received accept signal");
ci->accept = true;
goto retry;
}
if (!strncasecmp(buf, "reject", 6)) {
if (cmdmatch(buf, "reject")) {
LOGDEBUG("Connector received reject signal");
ci->accept = false;
goto retry;
}
if (!strncasecmp(buf, "loglevel", 8)) {
if (cmdmatch(buf, "loglevel")) {
sscanf(buf, "loglevel=%d", &ckp->loglevel);
goto retry;
}
LOGDEBUG("Connector received message: %s", buf);
if (!strncasecmp(buf, "shutdown", 8))
if (cmdmatch(buf, "shutdown"))
goto out;
if (!strncasecmp(buf, "dropclient", 10)) {
if (cmdmatch(buf, "dropclient")) {
client_instance_t *client;
int client_id;
@ -556,7 +559,7 @@ retry:
LOGINFO("Connector dropped client id: %d", client_id);
goto retry;
}
if (!strncasecmp(buf, "getfd", 5)) {
if (cmdmatch(buf, "getfd")) {
send_fd(ci->serverfd, sockd);
goto retry;
}
@ -595,6 +598,8 @@ int connector(proc_instance_t *pi)
const int on = 1;
int tries = 0;
LOGWARNING("%s connector starting", ckp->name);
if (ckp->serverurl) {
if (!extract_sockaddr(ckp->serverurl, &url, &port)) {
LOGWARNING("Failed to extract server address from %s", ckp->serverurl);

17
src/generator.c

@ -193,6 +193,7 @@ static int gen_loop(proc_instance_t *pi)
server_instance_t *si = NULL;
unixsock_t *us = &pi->us;
ckpool_t *ckp = pi->ckp;
bool started = false;
char *buf = NULL;
connsock_t *cs;
gbtbase_t *gbt;
@ -255,8 +256,13 @@ retry:
LOGINFO("No best block hash support from %s:%s",
cs->url, cs->port);
send_unix_msg(sockd, "Failed");
} else
} else {
if (unlikely(!started)) {
started = true;
LOGWARNING("%s generator ready", ckp->name);
}
send_unix_msg(sockd, hash);
}
} else if (cmdmatch(buf, "getlast")) {
int height = get_blockcount(cs);
@ -269,6 +275,11 @@ retry:
send_unix_msg(sockd, "Failed");
goto reconnect;
} else {
if (unlikely(!started)) {
started = true;
LOGWARNING("%s generator ready", ckp->name);
}
send_unix_msg(sockd, hash);
LOGDEBUG("Hash: %s", hash);
}
@ -1330,6 +1341,8 @@ static int proxy_mode(ckpool_t *ckp, proc_instance_t *pi)
proxi->cs = &si->cs;
}
LOGWARNING("%s generator ready", ckp->name);
ret = proxy_loop(pi);
for (i = 0; i < ckp->proxies; i++) {
@ -1358,6 +1371,8 @@ int generator(proc_instance_t *pi)
ckpool_t *ckp = pi->ckp;
int ret;
LOGWARNING("%s generator starting", ckp->name);
if (ckp->proxy)
ret = proxy_mode(ckp, pi);
else

33
src/stratifier.c

@ -413,9 +413,23 @@ static void purge_share_hashtable(int64_t wb_id)
LOGINFO("Cleared %d shares from share hashtable", purged);
}
static void ckdbq_add(ckpool_t *ckp, const int idtype, json_t *val)
static char *status_chars = "|/-\\";
static void _ckdbq_add(ckpool_t *ckp, const int idtype, json_t *val, const char *file,
const char *func, const int line)
{
static int counter = 0;
ckdb_msg_t *msg;
char ch;
ch = status_chars[(counter++) & 0x3];
fprintf(stdout, "%c\r", ch);
fflush(stdout);
if (!val) {
LOGWARNING("Invalid json sent to ckdbq_add from %s %s:%d", file, func, line);
return;
}
if (ckp->standalone)
return json_decref(val);
@ -426,6 +440,8 @@ static void ckdbq_add(ckpool_t *ckp, const int idtype, json_t *val)
ckmsgq_add(ckdbq, msg);
}
#define ckdbq_add(ckp, idtype, val) _ckdbq_add(ckp, idtype, val, __FILE__, __func__, __LINE__)
static void send_workinfo(ckpool_t *ckp, workbase_t *wb)
{
char cdfield[64];
@ -696,6 +712,7 @@ static void update_notify(ckpool_t *ckp)
workpadding);
LOGDEBUG("Header: %s", header);
hex2bin(wb->headerbin, header, 112);
wb->txn_hashes = ckzalloc(1);
ck_rlock(&workbase_lock);
strcpy(wb->enonce1const, proxy_base.enonce1);
@ -2130,17 +2147,25 @@ out:
static void ckdbq_process(ckpool_t *ckp, ckdb_msg_t *data)
{
static bool failed = false;
bool logged = false;
char *buf = NULL;
while (!buf) {
buf = json_ckdb_call(ckp, ckdb_ids[data->idtype], data->val, logged);
if (unlikely(!buf)) {
LOGWARNING("Failed to talk to ckdb, queueing messages");
if (!failed) {
failed = true;
LOGWARNING("Failed to talk to ckdb, queueing messages");
}
sleep(5);
}
logged = true;
}
if (failed) {
failed = false;
LOGWARNING("Successfully resumed talking to ckdb");
}
LOGINFO("Got %s ckdb response: %s", ckdb_ids[data->idtype], buf);
free(buf);
}
@ -2426,6 +2451,8 @@ int stratifier(proc_instance_t *pi)
char *buf;
int ret;
LOGWARNING("%s stratifier starting", ckp->name);
/* Store this for use elsewhere */
hex2bin(scriptsig_header_bin, scriptsig_header, 41);
address_to_pubkeytxn(pubkeytxnbin, ckp->btcaddress);
@ -2464,6 +2491,8 @@ int stratifier(proc_instance_t *pi)
cklock_init(&share_lock);
LOGWARNING("%s stratifier ready", ckp->name);
ret = stratum_loop(ckp, pi);
out:
return process_exit(ckp, pi, ret);

Loading…
Cancel
Save