From a59958f4b6c576284e6bf83a9d4fcedf392e990b Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 19 Jun 2014 14:09:26 +1000 Subject: [PATCH 1/4] ckdb - message log and fix lp timestamp --- src/ckdb.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 7 deletions(-) diff --git a/src/ckdb.c b/src/ckdb.c index 1812e7de..34285827 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -654,7 +654,7 @@ static K_STORE *workinfo_store; // one in the current block static K_ITEM *workinfo_current; // last of previous block -static K_ITEM *workinfo_lp; +static tv_t *last_lp; // SHARES id.sharelog.json={...} typedef struct shares { @@ -889,6 +889,62 @@ static K_STORE *userstats_store; static char logname[512]; #define LOGFILE(_msg) rotating_log(logname, _msg) +void logmsg(int loglevel, const char *fmt, ...) +{ + int logfd = 0; + char *buf = NULL; + struct tm *tm; + time_t now_t; + va_list ap; + char stamp[128]; + char *extra = ""; + + now_t = time(NULL); + tm = localtime(&now_t); + snprintf(stamp, sizeof(stamp), + "[%d-%02d-%02d %02d:%02d:%02d]", + tm->tm_year + 1900, + tm->tm_mon + 1, + tm->tm_mday, + tm->tm_hour, + tm->tm_min, + tm->tm_sec); + + if (!fmt) { + fprintf(stderr, "%s %s() called without fmt\n", stamp, __func__); + return; + } + + if (!global_ckp) + extra = " !!NULL global_ckp!!"; + else + logfd = global_ckp->logfd; + + va_start(ap, fmt); + VASPRINTF(&buf, fmt, ap); + va_end(ap); + + if (logfd) { + FILE *LOGFP = global_ckp->logfp; + + flock(logfd, LOCK_EX); + fprintf(LOGFP, "%s %s", stamp, buf); + if (loglevel <= LOG_ERR && errno != 0) + fprintf(LOGFP, " with errno %d: %s", errno, strerror(errno)); + fprintf(LOGFP, "\n"); + flock(logfd, LOCK_UN); + } + if (loglevel <= LOG_WARNING) { + if (loglevel <= LOG_ERR && errno != 0) { + fprintf(stderr, "%s %s with errno %d: %s%s\n", + stamp, buf, errno, strerror(errno), extra); + } else + fprintf(stderr, "%s %s%s\n", stamp, buf, extra); + fflush(stderr); + } + free(buf); +} + static void setnow(tv_t *now) { ts_t spec; @@ -2282,11 +2338,11 @@ unparam: workinfo_root = add_to_ktree(workinfo_root, item, cmp_workinfo); k_add_head(workinfo_store, item); - // Remember last workinfo of last height + // Remember the lp 'now' when the height changes if (workinfo_current) { if (cmp_height(DATA_WORKINFO(workinfo_current)->coinbase1, DATA_WORKINFO(item)->coinbase1) != 0) - workinfo_lp = workinfo_current; + last_lp = &(DATA_WORKINFO(item)->createdate); } workinfo_current = item; @@ -3191,7 +3247,7 @@ static void clean_up(ckpool_t *ckp) static void setup_data() { K_TREE_CTX ctx[1]; - K_ITEM look; + K_ITEM look, *found; WORKINFO wi; transfer_list = k_new_list("Transfer", sizeof(TRANSFER), ALLOC_TRANSFER, LIMIT_TRANSFER, true); @@ -3247,7 +3303,10 @@ static void setup_data() wi.createdate.tv_sec = 0L; wi.createdate.tv_usec = 0L; look.data = (void *)(&wi); - workinfo_lp = find_before_in_ktree(workinfo_height_root, &look, cmp_workinfo_height, ctx); + // Find the first workinfo for this height + found = find_after_in_ktree(workinfo_height_root, &look, cmp_workinfo_height, ctx); + if (found) + last_lp = &(DATA_WORKINFO(found)->createdate); // No longer needed workinfo_height_root = free_ktree(workinfo_height_root, NULL); } @@ -3874,8 +3933,8 @@ static char *cmd_homepage(char *cmd, char *id, __maybe_unused tv_t *now, __maybe strcpy(buf, "ok."); off = strlen(buf); - if (workinfo_lp) { - tvs_to_buf(&(DATA_WORKINFO(workinfo_lp)->createdate), reply, sizeof(reply)); + if (last_lp) { + tvs_to_buf(last_lp, reply, sizeof(reply)); snprintf(tmp, sizeof(tmp), "lastlp=%s%c", reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); } else { @@ -4260,6 +4319,7 @@ int main(int argc, char **argv) int c, ret; char *kill; + global_ckp = &ckp; memset(&ckp, 0, sizeof(ckp)); ckp.loglevel = LOG_NOTICE; From 036e1b8143293477f8f8a586fcbb036c86afd650 Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 19 Jun 2014 14:20:10 +1000 Subject: [PATCH 2/4] php - display full accurate Network, Last Block --- pool/page.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pool/page.php b/pool/page.php index 954a1132..a020890f 100644 --- a/pool/page.php +++ b/pool/page.php @@ -180,10 +180,10 @@ function pgtop($dotop, $user, $douser) { $sec = $now - $info['lastlp']; $min = round($sec / 60); - $nlb = '~'.$min.'m'; -# $s = $sec % 60; -# if ($s > 0) -# $nlb .= " ${s}s"; + $nlb = $min.'m'; + $s = $sec % 60; + if ($s > 0) + $nlb .= " ${s}s"; } } From 414453357e6746424f959751667e3eabc7c7f1af Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 19 Jun 2014 14:25:37 +1000 Subject: [PATCH 3/4] ckdb - update last_lp comments --- src/ckdb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ckdb.c b/src/ckdb.c index 34285827..64e5b049 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -653,7 +653,8 @@ static K_LIST *workinfo_list; static K_STORE *workinfo_store; // one in the current block static K_ITEM *workinfo_current; -// last of previous block +// first workinfo of current block +// TODO: have it's own memory? static tv_t *last_lp; // SHARES id.sharelog.json={...} @@ -3943,6 +3944,7 @@ static char *cmd_homepage(char *cmd, char *id, __maybe_unused tv_t *now, __maybe } /* + // TODO: have a last_block - like last_lp - only updated when we find a block b_item = last_in_tree(blocks_root, ctx); if (b_item) { tvs_to_buf(&(DATA_BLOCKS(b_item)->createdate), reply, sizeof(reply)); From eb1977213c7f677d8ec7f4991894b4bc7b9a691d Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 19 Jun 2014 15:01:30 +1000 Subject: [PATCH 4/4] ckdb - change the longpoll abbreviation lp used, to the actual meaning: block change, but using the abbreviation bc --- pool/page.php | 6 +++--- src/ckdb.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pool/page.php b/pool/page.php index a020890f..dec1ba05 100644 --- a/pool/page.php +++ b/pool/page.php @@ -173,12 +173,12 @@ function pgtop($dotop, $user, $douser) } } - if (isset($info['lastlp'])) + if (isset($info['lastbc'])) { - $nlb = $info['lastlp']; + $nlb = $info['lastbc']; if ($nlb != '?') { - $sec = $now - $info['lastlp']; + $sec = $now - $info['lastbc']; $min = round($sec / 60); $nlb = $min.'m'; $s = $sec % 60; diff --git a/src/ckdb.c b/src/ckdb.c index 64e5b049..ea046ddf 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -655,7 +655,7 @@ static K_STORE *workinfo_store; static K_ITEM *workinfo_current; // first workinfo of current block // TODO: have it's own memory? -static tv_t *last_lp; +static tv_t *last_bc; // SHARES id.sharelog.json={...} typedef struct shares { @@ -2339,11 +2339,11 @@ unparam: workinfo_root = add_to_ktree(workinfo_root, item, cmp_workinfo); k_add_head(workinfo_store, item); - // Remember the lp 'now' when the height changes + // Remember the bc 'now' when the height changes if (workinfo_current) { if (cmp_height(DATA_WORKINFO(workinfo_current)->coinbase1, DATA_WORKINFO(item)->coinbase1) != 0) - last_lp = &(DATA_WORKINFO(item)->createdate); + last_bc = &(DATA_WORKINFO(item)->createdate); } workinfo_current = item; @@ -3307,7 +3307,7 @@ static void setup_data() // Find the first workinfo for this height found = find_after_in_ktree(workinfo_height_root, &look, cmp_workinfo_height, ctx); if (found) - last_lp = &(DATA_WORKINFO(found)->createdate); + last_bc = &(DATA_WORKINFO(found)->createdate); // No longer needed workinfo_height_root = free_ktree(workinfo_height_root, NULL); } @@ -3934,17 +3934,17 @@ static char *cmd_homepage(char *cmd, char *id, __maybe_unused tv_t *now, __maybe strcpy(buf, "ok."); off = strlen(buf); - if (last_lp) { - tvs_to_buf(last_lp, reply, sizeof(reply)); - snprintf(tmp, sizeof(tmp), "lastlp=%s%c", reply, FLDSEP); + if (last_bc) { + tvs_to_buf(last_bc, reply, sizeof(reply)); + snprintf(tmp, sizeof(tmp), "lastbc=%s%c", reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); } else { - snprintf(tmp, sizeof(tmp), "lastlp=?%c", FLDSEP); + snprintf(tmp, sizeof(tmp), "lastbc=?%c", FLDSEP); APPEND_REALLOC(buf, off, len, tmp); } /* - // TODO: have a last_block - like last_lp - only updated when we find a block + // TODO: have a last_block - like last_bc - only updated when we find a block b_item = last_in_tree(blocks_root, ctx); if (b_item) { tvs_to_buf(&(DATA_BLOCKS(b_item)->createdate), reply, sizeof(reply));