Browse Source

Merge branch 'master' of bitbucket.org:ckolivas/ckpool

master
Con Kolivas 10 years ago
parent
commit
6c5293a786
  1. BIN
      html/green.png
  2. BIN
      html/orange.png
  3. BIN
      html/red.png
  4. 48
      pool/page.php
  5. 31
      src/ckdb.c
  6. 14
      src/ckdb.h
  7. 48
      src/ckdb_cmd.c
  8. 13
      src/ckdb_data.c

BIN
html/green.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 B

BIN
html/orange.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 B

BIN
html/red.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 415 B

48
pool/page.php

@ -287,7 +287,55 @@ function pgtop($info, $dotop, $user, $douser)
$top .= '<div class=topd>'; $top .= '<div class=topd>';
if ($dotop === true) if ($dotop === true)
{ {
$lh = ''; $ls = ''; $lw = '';
if (isset($info['now']) && isset($info['lastsh'])
&& isset($info['lasthb']) && isset($info['lastwi']))
{
$lsn = $info['now'] - $info['lastsh'];
$lhn = $info['now'] - $info['lasthb'];
$lwn = $info['now'] - $info['lastwi'];
if ($lsn < 2)
$lsc = 'green';
else
{
if ($lsn < 4)
$lsc = 'orange';
else
$lsc = 'red';
}
if ($lhn < 3)
$lhc = 'green';
else
{
if ($lhn < 6)
$lhc = 'orange';
else
$lhc = 'red';
}
if ($lwn < 36)
$lwc = 'green';
else
{
if ($lwn < 46)
$lwc = 'orange';
else
$lwc = 'red';
}
$lsc = 'green';
$lhc = 'orange';
$lwc = 'red';
$img1 = '<img border=0 src=/';
$img2 = '.png>';
$ls = $img1.$lsc.$img2;
$lh = $img1.$lhc.$img2;
$lw = $img1.$lwc.$img2;
}
$top .= '<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td>'; $top .= '<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td>';
$top .= '<table cellpadding=1 cellspacing=0 border=0>';
$top .= "<tr><td class=topdes>$lh</td></tr>";
$top .= "<tr><td class=topdes>$ls</td></tr>";
$top .= "<tr><td class=topdes>$lw</td></tr></table>";
$top .= '</td><td>';
$top .= '<table cellpadding=1 cellspacing=0 border=0 width=100%>'; $top .= '<table cellpadding=1 cellspacing=0 border=0 width=100%>';
$top .= '<tr><td class=topdes>CKPool:&nbsp;</td>'; $top .= '<tr><td class=topdes>CKPool:&nbsp;</td>';
$top .= "<td class=topdat>&nbsp;$phr</td></tr>"; $top .= "<td class=topdat>&nbsp;$phr</td></tr>";

31
src/ckdb.c

@ -170,6 +170,14 @@ const char *hashpatt = "^[A-Fa-f0-9]*$";
* bitcoind is used to fully validate them when required */ * bitcoind is used to fully validate them when required */
const char *addrpatt = "^[13][A-HJ-NP-Za-km-z1-9]*$"; const char *addrpatt = "^[13][A-HJ-NP-Za-km-z1-9]*$";
/* These are included in cmd_homepage
* to help identify when ckpool locks up (or dies) */
tv_t last_heartbeat;
tv_t last_workinfo;
tv_t last_share;
tv_t last_auth;
cklock_t last_lock;
// So the records below have the same 'name' as the klist // So the records below have the same 'name' as the klist
const char Transfer[] = "Transfer"; const char Transfer[] = "Transfer";
@ -280,6 +288,13 @@ bool startup_complete = false;
// Tell everyone to die // Tell everyone to die
bool everyone_die = false; bool everyone_die = false;
/* These are included in cmd_homepage
* to help identify when ckpool locks up (or dies) */
tv_t last_heartbeat;
tv_t last_workinfo;
tv_t last_share;
tv_t last_auth;
static cklock_t fpm_lock; static cklock_t fpm_lock;
static char *first_pool_message; static char *first_pool_message;
static sem_t socketer_sem; static sem_t socketer_sem;
@ -3207,6 +3222,16 @@ static void *listener(void *arg)
LOGWARNING("%s(): ckdb ready, queue %d", __func__, wqcount); LOGWARNING("%s(): ckdb ready, queue %d", __func__, wqcount);
/* Until startup_complete, the values should be ignored
* Setting them to 'now' means that they won't time out
* until after startup_complete */
ck_wlock(&last_lock);
setnow(&last_heartbeat);
copy_tv(&last_workinfo, &last_heartbeat);
copy_tv(&last_share, &last_heartbeat);
copy_tv(&last_auth, &last_heartbeat);
ck_wunlock(&last_lock);
startup_complete = true; startup_complete = true;
} }
@ -3219,9 +3244,9 @@ static void *listener(void *arg)
wq_item = k_unlink_head(workqueue_store); wq_item = k_unlink_head(workqueue_store);
K_WUNLOCK(workqueue_store); K_WUNLOCK(workqueue_store);
/* Don't keep a connection for more than ~10s or ~1000 items /* Don't keep a connection for more than ~10s or ~10000 items
* but always have a connection open */ * but always have a connection open */
if ((time(NULL) - now) > 10 || wqgot > 1000) { if ((time(NULL) - now) > 10 || wqgot > 10000) {
PQfinish(conn); PQfinish(conn);
conn = dbconnect(); conn = dbconnect();
now = time(NULL); now = time(NULL);
@ -4056,6 +4081,8 @@ int main(int argc, char **argv)
ckp.main.ckp = &ckp; ckp.main.ckp = &ckp;
ckp.main.processname = strdup("main"); ckp.main.processname = strdup("main");
cklock_init(&last_lock);
if (confirm_sharesummary) { if (confirm_sharesummary) {
// TODO: add a system lock to stop running 2 at once? // TODO: add a system lock to stop running 2 at once?
confirm_summaries(); confirm_summaries();

14
src/ckdb.h

@ -52,7 +52,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "0.9.6" #define DB_VERSION "0.9.6"
#define CKDB_VERSION DB_VERSION"-0.903" #define CKDB_VERSION DB_VERSION"-0.910"
#define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #define WHERE_FFL_HERE __FILE__, __func__, __LINE__
@ -197,6 +197,7 @@ enum data_type {
TYPE_TV, TYPE_TV,
TYPE_TVS, TYPE_TVS,
TYPE_CTV, TYPE_CTV,
TYPE_FTV,
TYPE_BLOB, TYPE_BLOB,
TYPE_DOUBLE TYPE_DOUBLE
}; };
@ -266,6 +267,14 @@ extern bool startup_complete;
// Tell everyone to die // Tell everyone to die
extern bool everyone_die; extern bool everyone_die;
/* These are included in cmd_homepage
* to help identify when ckpool locks up (or dies) */
extern tv_t last_heartbeat;
extern tv_t last_workinfo;
extern tv_t last_share;
extern tv_t last_auth;
extern cklock_t last_lock;
#define JSON_TRANSFER "json=" #define JSON_TRANSFER "json="
#define JSON_TRANSFER_LEN (sizeof(JSON_TRANSFER)-1) #define JSON_TRANSFER_LEN (sizeof(JSON_TRANSFER)-1)
#define JSON_BEGIN '{' #define JSON_BEGIN '{'
@ -1558,6 +1567,7 @@ extern char *_data_to_buf(enum data_type typ, void *data, char *buf, size_t siz,
#define int_to_buf(_data, _buf, _siz) _int_to_buf(_data, _buf, _siz, WHERE_FFL_HERE) #define int_to_buf(_data, _buf, _siz) _int_to_buf(_data, _buf, _siz, WHERE_FFL_HERE)
#define tv_to_buf(_data, _buf, _siz) _tv_to_buf(_data, _buf, _siz, WHERE_FFL_HERE) #define tv_to_buf(_data, _buf, _siz) _tv_to_buf(_data, _buf, _siz, WHERE_FFL_HERE)
#define ctv_to_buf(_data, _buf, _siz) _ctv_to_buf(_data, _buf, _siz, WHERE_FFL_HERE) #define ctv_to_buf(_data, _buf, _siz) _ctv_to_buf(_data, _buf, _siz, WHERE_FFL_HERE)
#define ftv_to_buf(_data, _buf, _siz) _ftv_to_buf(_data, _buf, _siz, WHERE_FFL_HERE)
#define tvs_to_buf(_data, _buf, _siz) _tvs_to_buf(_data, _buf, _siz, WHERE_FFL_HERE) #define tvs_to_buf(_data, _buf, _siz) _tvs_to_buf(_data, _buf, _siz, WHERE_FFL_HERE)
//#define blob_to_buf(_data, _buf, _siz) _blob_to_buf(_data, _buf, _siz, WHERE_FFL_HERE) //#define blob_to_buf(_data, _buf, _siz) _blob_to_buf(_data, _buf, _siz, WHERE_FFL_HERE)
#define double_to_buf(_data, _buf, _siz) _double_to_buf(_data, _buf, _siz, WHERE_FFL_HERE) #define double_to_buf(_data, _buf, _siz) _double_to_buf(_data, _buf, _siz, WHERE_FFL_HERE)
@ -1568,6 +1578,8 @@ extern char *_int_to_buf(int32_t data, char *buf, size_t siz, WHERE_FFL_ARGS);
extern char *_tv_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS); extern char *_tv_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS);
// Convert tv to S,uS // Convert tv to S,uS
extern char *_ctv_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS); extern char *_ctv_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS);
// Convert tv to S.uS
extern char *_ftv_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS);
// Convert tv to seconds (ignore uS) // Convert tv to seconds (ignore uS)
extern char *_tvs_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS); extern char *_tvs_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS);
/* unused yet /* unused yet

48
src/ckdb_cmd.c

@ -1823,6 +1823,11 @@ static char *cmd_sharelog(PGconn *conn, char *cmd, char *id,
if (workinfoid == -1) { if (workinfoid == -1) {
LOGERR("%s(%s) %s.failed.DBE", __func__, cmd, id); LOGERR("%s(%s) %s.failed.DBE", __func__, cmd, id);
return strdup("failed.DBE"); return strdup("failed.DBE");
} else {
// Only flag a successful workinfo
ck_wlock(&last_lock);
setnow(&last_workinfo);
ck_wunlock(&last_lock);
} }
LOGDEBUG("%s.ok.added %"PRId64, id, workinfoid); LOGDEBUG("%s.ok.added %"PRId64, id, workinfoid);
wiconf: wiconf:
@ -1909,6 +1914,11 @@ wiconf:
if (!ok) { if (!ok) {
LOGERR("%s(%s) %s.failed.DATA", __func__, cmd, id); LOGERR("%s(%s) %s.failed.DATA", __func__, cmd, id);
return strdup("failed.DATA"); return strdup("failed.DATA");
} else {
// Only flag a successful share
ck_wlock(&last_lock);
setnow(&last_share);
ck_wunlock(&last_lock);
} }
LOGDEBUG("%s.ok.added %s", id, transfer_data(i_nonce)); LOGDEBUG("%s.ok.added %s", id, transfer_data(i_nonce));
sconf: sconf:
@ -2237,8 +2247,12 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by,
if (!ok) { if (!ok) {
LOGDEBUG("%s() %s.failed.DBE", __func__, id); LOGDEBUG("%s() %s.failed.DBE", __func__, id);
return strdup("failed.DBE"); return strdup("failed.DBE");
} else {
// Only flag a successful auth
ck_wlock(&last_lock);
setnow(&last_auth);
ck_wunlock(&last_lock);
} }
snprintf(reply, siz, snprintf(reply, siz,
"ok.authorise={\"secondaryuserid\":\"%s\"," "ok.authorise={\"secondaryuserid\":\"%s\","
"\"difficultydefault\":%d}", "\"difficultydefault\":%d}",
@ -2321,8 +2335,12 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by,
if (!ok) { if (!ok) {
LOGDEBUG("%s() %s.failed.DBE", __func__, id); LOGDEBUG("%s() %s.failed.DBE", __func__, id);
return strdup("failed.DBE"); return strdup("failed.DBE");
} else {
// Only flag a successful auth
ck_wlock(&last_lock);
setnow(&last_auth);
ck_wunlock(&last_lock);
} }
snprintf(reply, siz, snprintf(reply, siz,
"ok.addrauth={\"secondaryuserid\":\"%s\"," "ok.addrauth={\"secondaryuserid\":\"%s\","
"\"difficultydefault\":%d}", "\"difficultydefault\":%d}",
@ -2367,6 +2385,10 @@ static char *cmd_heartbeat(__maybe_unused PGconn *conn, char *cmd, char *id,
if (!startup_complete) if (!startup_complete)
goto pulse; goto pulse;
ck_wlock(&last_lock);
setnow(&last_heartbeat);
ck_wunlock(&last_lock);
K_WLOCK(heartbeatqueue_free); K_WLOCK(heartbeatqueue_free);
if (heartbeatqueue_store->count == 0) { if (heartbeatqueue_store->count == 0) {
K_WUNLOCK(heartbeatqueue_free); K_WUNLOCK(heartbeatqueue_free);
@ -2413,7 +2435,7 @@ pulse:
} }
static char *cmd_homepage(__maybe_unused PGconn *conn, char *cmd, char *id, static char *cmd_homepage(__maybe_unused PGconn *conn, char *cmd, char *id,
__maybe_unused tv_t *now, __maybe_unused char *by, tv_t *now, __maybe_unused char *by,
__maybe_unused char *code, __maybe_unused char *inet, __maybe_unused char *code, __maybe_unused char *inet,
__maybe_unused tv_t *notcd, K_TREE *trf_root) __maybe_unused tv_t *notcd, K_TREE *trf_root)
{ {
@ -2437,6 +2459,26 @@ static char *cmd_homepage(__maybe_unused PGconn *conn, char *cmd, char *id,
APPEND_REALLOC_INIT(buf, off, len); APPEND_REALLOC_INIT(buf, off, len);
APPEND_REALLOC(buf, off, len, "ok."); APPEND_REALLOC(buf, off, len, "ok.");
// N.B. cmd_homepage isn't called until startup_complete
ftv_to_buf(now, reply, siz);
snprintf(tmp, sizeof(tmp), "now=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
ck_wlock(&last_lock);
ftv_to_buf(&last_heartbeat, reply, siz);
snprintf(tmp, sizeof(tmp), "lasthb=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
ftv_to_buf(&last_workinfo, reply, siz);
snprintf(tmp, sizeof(tmp), "lastwi=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
ftv_to_buf(&last_share, reply, siz);
snprintf(tmp, sizeof(tmp), "lastsh=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
ftv_to_buf(&last_auth, reply, siz);
ck_wunlock(&last_lock);
snprintf(tmp, sizeof(tmp), "lastau=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
if (last_bc.tv_sec) { if (last_bc.tv_sec) {
tvs_to_buf(&last_bc, reply, siz); tvs_to_buf(&last_bc, reply, siz);
snprintf(tmp, sizeof(tmp), "lastbc=%s%c", reply, FLDSEP); snprintf(tmp, sizeof(tmp), "lastbc=%s%c", reply, FLDSEP);

13
src/ckdb_data.c

@ -358,6 +358,7 @@ void _txt_to_double(char *nam, char *fld, double *data, size_t siz, WHERE_FFL_AR
char *_data_to_buf(enum data_type typ, void *data, char *buf, size_t siz, WHERE_FFL_ARGS) char *_data_to_buf(enum data_type typ, void *data, char *buf, size_t siz, WHERE_FFL_ARGS)
{ {
struct tm tm; struct tm tm;
double d;
if (!buf) { if (!buf) {
switch (typ) { switch (typ) {
@ -376,6 +377,7 @@ char *_data_to_buf(enum data_type typ, void *data, char *buf, size_t siz, WHERE_
siz = DATE_BUFSIZ; siz = DATE_BUFSIZ;
break; break;
case TYPE_CTV: case TYPE_CTV:
case TYPE_FTV:
siz = CDATE_BUFSIZ; siz = CDATE_BUFSIZ;
break; break;
case TYPE_DOUBLE: case TYPE_DOUBLE:
@ -419,6 +421,11 @@ char *_data_to_buf(enum data_type typ, void *data, char *buf, size_t siz, WHERE_
(((tv_t *)data)->tv_sec), (((tv_t *)data)->tv_sec),
(((tv_t *)data)->tv_usec)); (((tv_t *)data)->tv_usec));
break; break;
case TYPE_FTV:
d = (double)(((tv_t *)data)->tv_sec) +
(double)(((tv_t *)data)->tv_usec) / 1000000.0;
snprintf(buf, siz, "%.6f", d);
break;
case TYPE_TVS: case TYPE_TVS:
snprintf(buf, siz, "%ld", (((tv_t *)data)->tv_sec)); snprintf(buf, siz, "%ld", (((tv_t *)data)->tv_sec));
break; break;
@ -456,6 +463,12 @@ char *_ctv_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS)
return _data_to_buf(TYPE_CTV, (void *)data, buf, siz, WHERE_FFL_PASS); return _data_to_buf(TYPE_CTV, (void *)data, buf, siz, WHERE_FFL_PASS);
} }
// Convert tv to S.uS
char *_ftv_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS)
{
return _data_to_buf(TYPE_FTV, (void *)data, buf, siz, WHERE_FFL_PASS);
}
// Convert tv to seconds (ignore uS) // Convert tv to seconds (ignore uS)
char *_tvs_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS) char *_tvs_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS)
{ {

Loading…
Cancel
Save