Browse Source

ckdb/php - show only recent workers with an option to disable it

master
kanoi 10 years ago
parent
commit
c42de09e5c
  1. 2
      pool/page.php
  2. 33
      pool/page_workmgt.php
  3. 4
      src/ckdb.h
  4. 83
      src/ckdb_cmd.c

2
pool/page.php

@ -165,7 +165,7 @@ function pghead($script_marker, $name)
$head .= "window.onpaint=jst();\n</script>\n";
$head .= "<style type='text/css'>
input {vertical-align: -2px;}
input[type=checkbox] {vertical-align: -2px;}
form {display: inline-block;}
html, body {height: 100%; font-family:Arial, Verdana, sans-serif; font-size:12pt; background-color:#eeffff; text-align: center; background-repeat: no-repeat; background-position: center;}
.page {min-height: 100%; height: auto !important; height: 100%; margin: 0 auto -50px; position: relative;}

33
pool/page_workmgt.php

@ -7,6 +7,21 @@ function workmgtuser($data, $user, $err)
if ($err != '')
$pg .= "<span class=err>$err<br><br></span>";
$ans = getWorkers($user, 'N');
if ($ans['STATUS'] == 'ok')
{
if (isset($ans['oldworkers']) && $ans['oldworkers'] == '0')
$chk = '';
else
$chk = ' checked';
$pg .= makeForm('workmgt');
$pg .= '<span>Active workers (7 days)';
$pg .= "<input type=checkbox name=seven$chk>";
$pg .= '<input type=submit name=S value=Update>';
$pg .= '</span></form><br><br>';
}
$pg .= makeForm('workmgt');
$pg .= "<table callpadding=0 cellspacing=0 border=0>\n";
$pg .= '<tr class=title>';
@ -14,8 +29,6 @@ function workmgtuser($data, $user, $err)
$pg .= '<td class=dr>Minimum Diff</td>';
$pg .= '</tr>';
$ans = getWorkers($user, 'N');
$offset = 0;
if ($ans['STATUS'] == 'ok')
{
@ -58,6 +71,21 @@ function workmgtuser($data, $user, $err)
function doworkmgt($data, $user)
{
$err = '';
$S = getparam('S', false);
$chk = getparam('seven', false);
if ($S == 'Update')
{
$settings = array();
if ($chk == 'on')
$settings['oldworkers'] = '7';
else
$settings['oldworkers'] = '0';
$ans = workerSet($user, $settings);
if ($ans['STATUS'] != 'ok')
$err = $ans['ERROR'];
}
else
{
$OK = getparam('OK', false);
$count = getparam('rows', false);
if ($OK == 'OK' && !nuem($count))
@ -80,6 +108,7 @@ function doworkmgt($data, $user)
$err = $ans['ERROR'];
}
}
}
$pg = workmgtuser($data, $user, $err);

4
src/ckdb.h

@ -55,7 +55,7 @@
#define DB_VLOCK "1"
#define DB_VERSION "1.0.0"
#define CKDB_VERSION DB_VERSION"-1.042"
#define CKDB_VERSION DB_VERSION"-1.043"
#define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__
@ -801,6 +801,8 @@ extern K_STORE *useratts_store;
// This att means the user uses multiple % based payout addresses
#define USER_MULTI_PAYOUT "PayAddresses"
#define USER_OLD_WORKERS "OldWorkersDays"
#define USER_OLD_WORKERS_DEFAULT 7
// WORKERS
typedef struct workers {

83
src/ckdb_cmd.c

@ -408,16 +408,18 @@ struckout:
}
static char *cmd_workerset(PGconn *conn, char *cmd, char *id, tv_t *now,
char *by, char *code, char *inet,
__maybe_unused tv_t *notcd, K_TREE *trf_root)
char *by, char *code, char *inet, tv_t *cd,
K_TREE *trf_root)
{
K_ITEM *i_username, *i_workername, *i_diffdef, *u_item, *w_item;
K_ITEM *i_username, *i_workername, *i_diffdef, *i_oldworkers;
K_ITEM *u_item, *ua_item, *w_item;
HEARTBEATQUEUE *heartbeatqueue;
K_ITEM *hq_item;
char workername_buf[32]; // 'workername:' + digits
char diffdef_buf[32]; // 'difficultydefault:' + digits
char reply[1024] = "";
size_t siz = sizeof(reply);
USERATTS *useratts;
WORKERS *workers;
USERS *users;
int32_t difficultydefault;
@ -448,6 +450,37 @@ static char *cmd_workerset(PGconn *conn, char *cmd, char *id, tv_t *now,
// Default answer if no problems
answer = strdup("updated");
i_oldworkers = optional_name(trf_root, "oldworkers",
1, NULL, reply, siz);
if (i_oldworkers) {
bool update = false;
int64_t new_ow = atol(transfer_data(i_oldworkers));
K_RLOCK(useratts_free);
ua_item = find_useratts(users->userid, USER_OLD_WORKERS);
K_RUNLOCK(useratts_free);
if (!ua_item) {
if (new_ow != USER_OLD_WORKERS_DEFAULT)
update = true;
} else {
DATA_USERATTS(useratts, ua_item);
if (new_ow != useratts->attnum)
update = true;
}
if (update) {
ua_item = useratts_add(conn, users->username,
USER_OLD_WORKERS, EMPTY,
EMPTY, EMPTY,
transfer_data(i_oldworkers),
EMPTY, EMPTY, EMPTY,
by, code, inet, cd,
trf_root, false);
if (!ua_item)
reason = "Invalid";
}
goto kazuki;
}
// Loop through the list of workers and do any changes
for (workernum = 0; workernum < 9999; workernum++) {
snprintf(workername_buf, sizeof(workername_buf),
@ -524,6 +557,7 @@ static char *cmd_workerset(PGconn *conn, char *cmd, char *id, tv_t *now,
}
}
kazuki:
struckout:
if (reason) {
if (answer)
@ -1336,8 +1370,7 @@ static char *cmd_percent(char *cmd, char *id, tv_t *now, USERS *users)
DATA_WORKERS_NULL(workers, w_item);
while (w_item && workers->userid == users->userid) {
if (CURRENT(&(workers->expirydate))) {
ws_item = find_workerstatus(users->userid, workers->workername,
__FILE__, __func__, __LINE__);
ws_item = get_workerstatus(users->userid, workers->workername);
if (ws_item) {
DATA_WORKERSTATUS(workerstatus, ws_item);
t_diffacc += workerstatus->diffacc;
@ -1520,10 +1553,13 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
WORKERS lookworkers, *workers;
WORKERSTATUS *workerstatus;
USERSTATS *userstats;
USERATTS *useratts;
USERS *users;
char reply[1024] = "";
char tmp[1024];
int64_t oldworkers = USER_OLD_WORKERS_DEFAULT;
size_t siz = sizeof(reply);
tv_t last_share;
char *buf;
size_t len, off;
bool stats, percent;
@ -1561,6 +1597,14 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
if (percent)
return cmd_percent(cmd, id, now, users);
K_RLOCK(useratts_free);
ua_item = find_useratts(users->userid, USER_OLD_WORKERS);
K_RUNLOCK(useratts_free);
if (ua_item) {
DATA_USERATTS(useratts, ua_item);
oldworkers = useratts->attnum;
}
APPEND_REALLOC_INIT(buf, off, len);
APPEND_REALLOC(buf, off, len, "ok.");
snprintf(tmp, sizeof(tmp), "blockacc=%.1f%c",
@ -1569,6 +1613,13 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
snprintf(tmp, sizeof(tmp), "blockreward=%"PRId64"%c",
pool.reward, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
snprintf(tmp, sizeof(tmp), "oldworkers=%"PRId64"%c",
oldworkers, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
if (oldworkers > 0)
oldworkers *= 24L * 60L * 60L;
else
oldworkers = now->tv_sec + 1;
INIT_WORKERS(&w_look);
@ -1582,6 +1633,16 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
rows = 0;
while (w_item && workers->userid == users->userid) {
if (CURRENT(&(workers->expirydate))) {
ws_item = get_workerstatus(users->userid, workers->workername);
if (ws_item) {
DATA_WORKERSTATUS(workerstatus, ws_item);
K_RLOCK(workerstatus_free);
copy_tv(&last_share, &(workerstatus->last_share));
K_RUNLOCK(workerstatus_free);
} else
last_share.tv_sec = last_share.tv_usec = 0L;
if (tvdiff(now, &last_share) < oldworkers) {
str_to_buf(workers->workername, reply, sizeof(reply));
snprintf(tmp, sizeof(tmp), "workername:%d=%s%c", rows, reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
@ -1613,6 +1674,8 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
w_hashrate5m = w_hashrate1hr =
w_hashrate24hr = 0.0;
w_elapsed = -1;
if (!ws_item) {
w_lastshare.tv_sec = 0;
w_lastdiff = w_diffacc = w_diffinv =
w_diffsta = w_diffdup =
@ -1620,11 +1683,10 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
w_shareacc = w_shareinv =
w_sharesta = w_sharedup =
w_sharehi = w_sharerej = 0;
ws_item = find_workerstatus(users->userid, workers->workername,
__FILE__, __func__, __LINE__);
if (ws_item) {
} else {
DATA_WORKERSTATUS(workerstatus, ws_item);
// It's bad to read possibly changing data
K_RLOCK(workerstatus_free);
w_lastshare.tv_sec = workerstatus->last_share.tv_sec;
w_lastdiff = workerstatus->last_diff;
w_diffacc = workerstatus->diffacc;
@ -1639,6 +1701,7 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
w_sharedup = workerstatus->sharedup;
w_sharehi = workerstatus->sharehi;
w_sharerej = workerstatus->sharerej;
K_RUNLOCK(workerstatus_free);
}
/* TODO: workers_root userid+worker is ordered
@ -1731,9 +1794,9 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
snprintf(tmp, sizeof(tmp), "w_sharerej:%d=%s%c", rows, reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
}
rows++;
}
}
w_item = next_in_ktree(w_ctx);
DATA_WORKERS_NULL(workers, w_item);
}

Loading…
Cancel
Save