kanoi 11 years ago
parent
commit
fa7567a99d
  1. 27
      src/ckpool.c
  2. 4
      src/connector.c
  3. 4
      src/generator.c
  4. 15
      src/stratifier.c

27
src/ckpool.c

@ -130,6 +130,17 @@ void ckmsgq_add(ckmsgq_t *ckmsgq, void *data)
mutex_unlock(&ckmsgq->lock); mutex_unlock(&ckmsgq->lock);
} }
static void broadcast_proc(ckpool_t *ckp, const char *buf)
{
int i;
for (i = 0; i < ckp->proc_instances; i++) {
proc_instance_t *pi = ckp->children[i];
send_proc(pi, buf);
}
}
/* Listen for incoming global requests. Always returns a response if possible */ /* Listen for incoming global requests. Always returns a response if possible */
static void *listener(void *arg) static void *listener(void *arg)
{ {
@ -159,6 +170,20 @@ retry:
} else if (!strncasecmp(buf, "ping", 4)) { } else if (!strncasecmp(buf, "ping", 4)) {
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)) {
int loglevel;
if (sscanf(buf, "loglevel=%d", &loglevel) != 1) {
LOGWARNING("Failed to parse loglevel message %s", buf);
send_unix_msg(sockd, "Failed");
} else if (loglevel < LOG_EMERG || loglevel > LOG_DEBUG) {
LOGWARNING("Invalid loglevel %d sent", loglevel);
send_unix_msg(sockd, "Invalid");
} else {
ckp->loglevel = loglevel;
broadcast_proc(ckp, buf);
send_unix_msg(sockd, "success");
}
} else if (!strncasecmp(buf, "getfd", 5)) { } else if (!strncasecmp(buf, "getfd", 5)) {
char *msg; char *msg;
@ -504,7 +529,7 @@ static bool write_pid(ckpool_t *ckp, const char *path, pid_t pid)
if (!stat(path, &statbuf)) { if (!stat(path, &statbuf)) {
int oldpid; int oldpid;
LOGWARNING("File %s exists", path); LOGNOTICE("File %s exists", path);
fp = fopen(path, "r"); fp = fopen(path, "r");
if (!fp) { if (!fp) {
LOGEMERG("Failed to open file %s", path); LOGEMERG("Failed to open file %s", path);

4
src/connector.c

@ -506,6 +506,10 @@ retry:
ci->accept = false; ci->accept = false;
goto retry; goto retry;
} }
if (!strncasecmp(buf, "loglevel", 8)) {
sscanf(buf, "loglevel=%d", &ckp->loglevel);
goto retry;
}
LOGDEBUG("Connector received message: %s", buf); LOGDEBUG("Connector received message: %s", buf);
if (!strncasecmp(buf, "shutdown", 8)) if (!strncasecmp(buf, "shutdown", 8))

4
src/generator.c

@ -279,6 +279,8 @@ retry:
LOGNOTICE("Submitting block data!"); LOGNOTICE("Submitting block data!");
if (submit_block(cs, buf + 12)) if (submit_block(cs, buf + 12))
send_proc(ckp->stratifier, "block"); send_proc(ckp->stratifier, "block");
} else if (!strncasecmp(buf, "loglevel", 8)) {
sscanf(buf, "loglevel=%d", &ckp->loglevel);
} else if (!strncasecmp(buf, "ping", 4)) { } else if (!strncasecmp(buf, "ping", 4)) {
LOGDEBUG("Generator received ping request"); LOGDEBUG("Generator received ping request");
send_unix_msg(sockd, "pong"); send_unix_msg(sockd, "pong");
@ -1253,6 +1255,8 @@ retry:
pthread_cancel(proxi->pth_precv); pthread_cancel(proxi->pth_precv);
pthread_cancel(proxi->pth_psend); pthread_cancel(proxi->pth_psend);
goto reconnect; goto reconnect;
} else if (!strncasecmp(buf, "loglevel", 8)) {
sscanf(buf, "loglevel=%d", &ckp->loglevel);
} else if (!strncasecmp(buf, "ping", 4)) { } else if (!strncasecmp(buf, "ping", 4)) {
LOGDEBUG("Proxy received ping request"); LOGDEBUG("Proxy received ping request");
send_unix_msg(sockd, "pong"); send_unix_msg(sockd, "pong");

15
src/stratifier.c

@ -195,6 +195,7 @@ struct user_instance {
tv_t last_share; tv_t last_share;
time_t last_stats; time_t last_stats;
time_t start_time;
double dsps1; double dsps1;
double dsps5; double dsps5;
@ -962,6 +963,8 @@ retry:
} else if (!strncasecmp(buf, "block", 5)) { } else if (!strncasecmp(buf, "block", 5)) {
block_solve(ckp); block_solve(ckp);
update_base(ckp); update_base(ckp);
} else if (!strncasecmp(buf, "loglevel", 8)) {
sscanf(buf, "loglevel=%d", &ckp->loglevel);
} else { } else {
json_t *val = json_loads(buf, 0, NULL); json_t *val = json_loads(buf, 0, NULL);
@ -1110,9 +1113,13 @@ static user_instance_t *authorise_user(const char *workername)
ck_ilock(&instance_lock); ck_ilock(&instance_lock);
HASH_FIND_STR(user_instances, username, instance); HASH_FIND_STR(user_instances, username, instance);
if (!instance) { if (!instance) {
ts_t now;
/* New user instance */ /* New user instance */
instance = ckzalloc(sizeof(user_instance_t)); instance = ckzalloc(sizeof(user_instance_t));
strcpy(instance->username, username); strcpy(instance->username, username);
ts_realtime(&now);
instance->start_time = now.tv_sec;
ck_ulock(&instance_lock); ck_ulock(&instance_lock);
instance->id = user_instance_id++; instance->id = user_instance_id++;
@ -2020,16 +2027,19 @@ static void update_userstats(ckpool_t *ckp)
ck_rlock(&instance_lock); ck_rlock(&instance_lock);
HASH_ITER(hh, user_instances, instance, tmp) { HASH_ITER(hh, user_instances, instance, tmp) {
double ghs1, ghs5, ghs60, ghs1440; double ghs1, ghs5, ghs60, ghs1440;
int elapsed;
if (instance->last_stats > now_t - 600) if (instance->last_stats > now_t - 600)
continue; continue;
elapsed = now_t - instance->start_time;
instance->last_stats = now_t; instance->last_stats = now_t;
ghs1 = instance->dsps1 * nonces; ghs1 = instance->dsps1 * nonces;
ghs5 = instance->dsps5 * nonces; ghs5 = instance->dsps5 * nonces;
ghs60 = instance->dsps60 * nonces; ghs60 = instance->dsps60 * nonces;
ghs1440 = instance->dsps1440 * nonces; ghs1440 = instance->dsps1440 * nonces;
val = json_pack("{ss,ss,sf,sf,sf,sf,ss,ss,ss,ss}", val = json_pack("{ss,si,ss,sf,sf,sf,sf,ss,ss,ss,ss}",
"poolinstance", ckp->name, "poolinstance", ckp->name,
"elapsed", elapsed,
"username", instance->username, "username", instance->username,
"hashrate", ghs1, "hashrate", ghs1,
"hashrate5m", ghs5, "hashrate5m", ghs5,
@ -2196,8 +2206,9 @@ static void *statsupdate(void *arg)
ts_realtime(&ts_now); ts_realtime(&ts_now);
sprintf(cdfield, "%lu,%lu", ts_now.tv_sec, ts_now.tv_nsec); sprintf(cdfield, "%lu,%lu", ts_now.tv_sec, ts_now.tv_nsec);
val = json_pack("{ss,si,si,sf,sf,sf,sf,ss,ss,ss,ss}", val = json_pack("{ss,si,si,si,sf,sf,sf,sf,ss,ss,ss,ss}",
"poolinstance", ckp->name, "poolinstance", ckp->name,
"elapsed", diff.tv_sec,
"users", stats.users, "users", stats.users,
"workers", stats.workers, "workers", stats.workers,
"hashrate", ghs1, "hashrate", ghs1,

Loading…
Cancel
Save