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) { if (!buf) {
LOGWARNING("Failed to get message in listener"); LOGWARNING("Failed to get message in listener");
send_unix_msg(sockd, "failed"); send_unix_msg(sockd, "failed");
} else if (!strncasecmp(buf, "shutdown", 8)) { } else if (cmdmatch(buf, "shutdown")) {
LOGWARNING("Listener received shutdown message, terminating ckpool"); LOGWARNING("Listener received shutdown message, terminating ckpool");
send_unix_msg(sockd, "exiting"); send_unix_msg(sockd, "exiting");
goto out; goto out;
} else if (!strncasecmp(buf, "ping", 4)) { } else if (cmdmatch(buf, "ping")) {
LOGDEBUG("Listener received ping request"); LOGDEBUG("Listener received ping request");
send_unix_msg(sockd, "pong"); send_unix_msg(sockd, "pong");
} else if (!strncasecmp(buf, "loglevel", 8)) { } else if (cmdmatch(buf, "loglevel")) {
int loglevel; int loglevel;
if (sscanf(buf, "loglevel=%d", &loglevel) != 1) { if (sscanf(buf, "loglevel=%d", &loglevel) != 1) {
@ -216,7 +216,7 @@ retry:
broadcast_proc(ckp, buf); broadcast_proc(ckp, buf);
send_unix_msg(sockd, "success"); send_unix_msg(sockd, "success");
} }
} else if (!strncasecmp(buf, "getfd", 5)) { } else if (cmdmatch(buf, "getfd")) {
char *msg; char *msg;
msg = send_recv_proc(ckp->connector, "getfd"); 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; goto out;
} }
} while (selret < 1); } while (selret < 1);
LOGWARNING("%s connector ready", ckp->name);
retry: retry:
close(sockd); close(sockd);
sockd = accept(us->sockd, NULL, NULL); sockd = accept(us->sockd, NULL, NULL);
@ -514,30 +517,30 @@ retry:
LOGWARNING("Failed to get message in connector_loop"); LOGWARNING("Failed to get message in connector_loop");
goto retry; goto retry;
} }
if (!strncasecmp(buf, "ping", 4)) { if (cmdmatch(buf, "ping")) {
LOGDEBUG("Connector received ping request"); LOGDEBUG("Connector received ping request");
send_unix_msg(sockd, "pong"); send_unix_msg(sockd, "pong");
goto retry; goto retry;
} }
if (!strncasecmp(buf, "accept", 6)) { if (cmdmatch(buf, "accept")) {
LOGDEBUG("Connector received accept signal"); LOGDEBUG("Connector received accept signal");
ci->accept = true; ci->accept = true;
goto retry; goto retry;
} }
if (!strncasecmp(buf, "reject", 6)) { if (cmdmatch(buf, "reject")) {
LOGDEBUG("Connector received reject signal"); LOGDEBUG("Connector received reject signal");
ci->accept = false; ci->accept = false;
goto retry; goto retry;
} }
if (!strncasecmp(buf, "loglevel", 8)) { if (cmdmatch(buf, "loglevel")) {
sscanf(buf, "loglevel=%d", &ckp->loglevel); sscanf(buf, "loglevel=%d", &ckp->loglevel);
goto retry; goto retry;
} }
LOGDEBUG("Connector received message: %s", buf); LOGDEBUG("Connector received message: %s", buf);
if (!strncasecmp(buf, "shutdown", 8)) if (cmdmatch(buf, "shutdown"))
goto out; goto out;
if (!strncasecmp(buf, "dropclient", 10)) { if (cmdmatch(buf, "dropclient")) {
client_instance_t *client; client_instance_t *client;
int client_id; int client_id;
@ -556,7 +559,7 @@ retry:
LOGINFO("Connector dropped client id: %d", client_id); LOGINFO("Connector dropped client id: %d", client_id);
goto retry; goto retry;
} }
if (!strncasecmp(buf, "getfd", 5)) { if (cmdmatch(buf, "getfd")) {
send_fd(ci->serverfd, sockd); send_fd(ci->serverfd, sockd);
goto retry; goto retry;
} }
@ -595,6 +598,8 @@ int connector(proc_instance_t *pi)
const int on = 1; const int on = 1;
int tries = 0; int tries = 0;
LOGWARNING("%s connector starting", ckp->name);
if (ckp->serverurl) { if (ckp->serverurl) {
if (!extract_sockaddr(ckp->serverurl, &url, &port)) { if (!extract_sockaddr(ckp->serverurl, &url, &port)) {
LOGWARNING("Failed to extract server address from %s", ckp->serverurl); 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; server_instance_t *si = NULL;
unixsock_t *us = &pi->us; unixsock_t *us = &pi->us;
ckpool_t *ckp = pi->ckp; ckpool_t *ckp = pi->ckp;
bool started = false;
char *buf = NULL; char *buf = NULL;
connsock_t *cs; connsock_t *cs;
gbtbase_t *gbt; gbtbase_t *gbt;
@ -255,8 +256,13 @@ retry:
LOGINFO("No best block hash support from %s:%s", LOGINFO("No best block hash support from %s:%s",
cs->url, cs->port); cs->url, cs->port);
send_unix_msg(sockd, "Failed"); send_unix_msg(sockd, "Failed");
} else } else {
if (unlikely(!started)) {
started = true;
LOGWARNING("%s generator ready", ckp->name);
}
send_unix_msg(sockd, hash); send_unix_msg(sockd, hash);
}
} else if (cmdmatch(buf, "getlast")) { } else if (cmdmatch(buf, "getlast")) {
int height = get_blockcount(cs); int height = get_blockcount(cs);
@ -269,6 +275,11 @@ retry:
send_unix_msg(sockd, "Failed"); send_unix_msg(sockd, "Failed");
goto reconnect; goto reconnect;
} else { } else {
if (unlikely(!started)) {
started = true;
LOGWARNING("%s generator ready", ckp->name);
}
send_unix_msg(sockd, hash); send_unix_msg(sockd, hash);
LOGDEBUG("Hash: %s", hash); LOGDEBUG("Hash: %s", hash);
} }
@ -1330,6 +1341,8 @@ static int proxy_mode(ckpool_t *ckp, proc_instance_t *pi)
proxi->cs = &si->cs; proxi->cs = &si->cs;
} }
LOGWARNING("%s generator ready", ckp->name);
ret = proxy_loop(pi); ret = proxy_loop(pi);
for (i = 0; i < ckp->proxies; i++) { for (i = 0; i < ckp->proxies; i++) {
@ -1358,6 +1371,8 @@ int generator(proc_instance_t *pi)
ckpool_t *ckp = pi->ckp; ckpool_t *ckp = pi->ckp;
int ret; int ret;
LOGWARNING("%s generator starting", ckp->name);
if (ckp->proxy) if (ckp->proxy)
ret = proxy_mode(ckp, pi); ret = proxy_mode(ckp, pi);
else 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); 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; 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) if (ckp->standalone)
return json_decref(val); 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); 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) static void send_workinfo(ckpool_t *ckp, workbase_t *wb)
{ {
char cdfield[64]; char cdfield[64];
@ -696,6 +712,7 @@ static void update_notify(ckpool_t *ckp)
workpadding); workpadding);
LOGDEBUG("Header: %s", header); LOGDEBUG("Header: %s", header);
hex2bin(wb->headerbin, header, 112); hex2bin(wb->headerbin, header, 112);
wb->txn_hashes = ckzalloc(1);
ck_rlock(&workbase_lock); ck_rlock(&workbase_lock);
strcpy(wb->enonce1const, proxy_base.enonce1); strcpy(wb->enonce1const, proxy_base.enonce1);
@ -2130,17 +2147,25 @@ out:
static void ckdbq_process(ckpool_t *ckp, ckdb_msg_t *data) static void ckdbq_process(ckpool_t *ckp, ckdb_msg_t *data)
{ {
static bool failed = false;
bool logged = false; bool logged = false;
char *buf = NULL; char *buf = NULL;
while (!buf) { while (!buf) {
buf = json_ckdb_call(ckp, ckdb_ids[data->idtype], data->val, logged); buf = json_ckdb_call(ckp, ckdb_ids[data->idtype], data->val, logged);
if (unlikely(!buf)) { 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); sleep(5);
} }
logged = true; logged = true;
} }
if (failed) {
failed = false;
LOGWARNING("Successfully resumed talking to ckdb");
}
LOGINFO("Got %s ckdb response: %s", ckdb_ids[data->idtype], buf); LOGINFO("Got %s ckdb response: %s", ckdb_ids[data->idtype], buf);
free(buf); free(buf);
} }
@ -2426,6 +2451,8 @@ int stratifier(proc_instance_t *pi)
char *buf; char *buf;
int ret; int ret;
LOGWARNING("%s stratifier starting", ckp->name);
/* Store this for use elsewhere */ /* Store this for use elsewhere */
hex2bin(scriptsig_header_bin, scriptsig_header, 41); hex2bin(scriptsig_header_bin, scriptsig_header, 41);
address_to_pubkeytxn(pubkeytxnbin, ckp->btcaddress); address_to_pubkeytxn(pubkeytxnbin, ckp->btcaddress);
@ -2464,6 +2491,8 @@ int stratifier(proc_instance_t *pi)
cklock_init(&share_lock); cklock_init(&share_lock);
LOGWARNING("%s stratifier ready", ckp->name);
ret = stratum_loop(ckp, pi); ret = stratum_loop(ckp, pi);
out: out:
return process_exit(ckp, pi, ret); return process_exit(ckp, pi, ret);

Loading…
Cancel
Save