Browse Source

Merge branch 'master' into multiproxy

master
Con Kolivas 10 years ago
parent
commit
45ea2ff4f9
  1. 995
      src/ckdb.c
  2. 241
      src/ckdb.h
  3. 102
      src/ckdb_cmd.c
  4. 59
      src/ckdb_data.c
  5. 182
      src/ckdb_dbio.c
  6. 4
      src/ckpool.c
  7. 10
      src/klist.c
  8. 3
      src/libckpool.h

995
src/ckdb.c

File diff suppressed because it is too large Load Diff

241
src/ckdb.h

@ -55,7 +55,7 @@
#define DB_VLOCK "1"
#define DB_VERSION "1.0.0"
#define CKDB_VERSION DB_VERSION"-1.066"
#define CKDB_VERSION DB_VERSION"-1.073"
#define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__
@ -102,8 +102,10 @@ extern int switch_state;
#define SWITCH_STATE_AUTHWORKERS 1
#define SWITCH_STATE_ALL 666666
#define BLANK " "
extern char *EMPTY;
// Field patterns
extern const char *userpatt;
extern const char *mailpatt;
extern const char *idpatt;
@ -237,7 +239,9 @@ enum data_type {
TYPE_CTV,
TYPE_FTV,
TYPE_BLOB,
TYPE_DOUBLE
TYPE_DOUBLE,
TYPE_T,
TYPE_BT
};
// BLOB does what PTR needs
@ -336,12 +340,27 @@ extern char *btc_server;
extern char *btc_auth;
extern int btc_timeout;
#define EDDB "expirydate"
#define CDDB "createdate"
#define CDTRF CDDB
#define BYDB "createby"
#define BYTRF BYDB
#define CODEDB "createcode"
#define CODETRF CODEDB
#define INETDB "createinet"
#define INETTRF INETDB
#define MDDB "modifydate"
#define MBYDB "modifyby"
#define MCODEDB "modifycode"
#define MINETDB "modifyinet"
extern char *by_default;
extern char *inet_default;
extern char *id_default;
enum cmd_values {
CMD_UNSET,
CMD_DUPSEQ, // Ignore, we've already got it
CMD_REPLY, // Means something was wrong - send back reply
CMD_TERMINATE,
CMD_PING,
@ -426,12 +445,16 @@ enum cmd_values {
// The size strdup will allocate multiples of
#define MEMBASE 4
#define LIST_MEM_ADD_SIZ(_list, _siz) do { \
if (_siz % MEMBASE) \
_siz += MEMBASE - (_siz % MEMBASE); \
_list->ram += (int)_siz; \
} while (0)
#define LIST_MEM_ADD(_list, _fld) do { \
size_t __siz; \
__siz = strlen(_fld) + 1; \
if (__siz % MEMBASE) \
__siz += MEMBASE - (__siz % MEMBASE); \
_list->ram += (int)__siz; \
LIST_MEM_ADD_SIZ(_list, __siz); \
} while (0)
#define LIST_MEM_SUB(_list, _fld) do { \
@ -470,7 +493,7 @@ enum cmd_values {
#define SET_MODIFYCODE(_list, _fld, _val) SET_POINTER(_list, _fld, _val, EMPTY)
#define SET_MODIFYINET(_list, _fld, _val) SET_POINTER(_list, _fld, _val, inet_default)
#define HISTORYDATECONTROL ",createdate,createby,createcode,createinet,expirydate"
#define HISTORYDATECONTROL ","CDDB","BYDB","CODEDB","INETDB","EDDB
#define HISTORYDATECOUNT 5
#define HISTORYDATECONTROLFIELDS \
tv_t createdate; \
@ -497,17 +520,17 @@ enum cmd_values {
size_t __siz = sizeof(__reply); \
K_ITEM *__item; \
TRANSFER *__transfer; \
__item = optional_name(_root, "createby", 1, NULL, __reply, __siz); \
__item = optional_name(_root, BYTRF, 1, NULL, __reply, __siz); \
if (__item) { \
DATA_TRANSFER(__transfer, __item); \
STRNCPY(_row->createby, __transfer->mvalue); \
} \
__item = optional_name(_root, "createcode", 1, NULL, __reply, __siz); \
__item = optional_name(_root, CODETRF, 1, NULL, __reply, __siz); \
if (__item) { \
DATA_TRANSFER(__transfer, __item); \
STRNCPY(_row->createcode, __transfer->mvalue); \
} \
__item = optional_name(_root, "createinet", 1, NULL, __reply, __siz); \
__item = optional_name(_root, INETTRF, 1, NULL, __reply, __siz); \
if (__item) { \
DATA_TRANSFER(__transfer, __item); \
STRNCPY(_row->createinet, __transfer->mvalue); \
@ -515,8 +538,8 @@ enum cmd_values {
} \
} while (0)
#define MODIFYDATECONTROL ",createdate,createby,createcode,createinet" \
",modifydate,modifyby,modifycode,modifyinet"
#define MODIFYDATECONTROL ","CDDB","BYDB","CODEDB","INETDB \
","MDDB","MBYDB","MCODEDB","MINETDB
#define MODIFYDATECOUNT 8
#define MODIFYUPDATECOUNT 4
#define MODIFYDATECONTROLFIELDS \
@ -595,17 +618,17 @@ enum cmd_values {
size_t __siz = sizeof(__reply); \
K_ITEM *__item; \
TRANSFER *__transfer; \
__item = optional_name(_root, "createby", 1, NULL, __reply, __siz); \
__item = optional_name(_root, BYTRF, 1, NULL, __reply, __siz); \
if (__item) { \
DATA_TRANSFER(__transfer, __item); \
SET_CREATEBY(_list, _row->createby, __transfer->mvalue); \
} \
__item = optional_name(_root, "createcode", 1, NULL, __reply, __siz); \
__item = optional_name(_root, CODETRF, 1, NULL, __reply, __siz); \
if (__item) { \
DATA_TRANSFER(__transfer, __item); \
SET_CREATECODE(_list, _row->createcode, __transfer->mvalue); \
} \
__item = optional_name(_root, "createinet", 1, NULL, __reply, __siz); \
__item = optional_name(_root, INETTRF, 1, NULL, __reply, __siz); \
if (__item) { \
DATA_TRANSFER(__transfer, __item); \
SET_CREATEINET(_list, _row->createinet, __transfer->mvalue); \
@ -614,7 +637,7 @@ enum cmd_values {
} \
} while (0)
#define SIMPLEDATECONTROL ",createdate,createby,createcode,createinet"
#define SIMPLEDATECONTROL ","CDDB","BYDB","CODEDB","INETDB
#define SIMPLEDATECOUNT 4
#define SIMPLEDATECONTROLFIELDS \
tv_t createdate; \
@ -645,17 +668,17 @@ enum cmd_values {
size_t __siz = sizeof(__reply); \
K_ITEM *__item; \
TRANSFER *__transfer; \
__item = optional_name(_root, "createby", 1, NULL, __reply, __siz); \
__item = optional_name(_root, BYTRF, 1, NULL, __reply, __siz); \
if (__item) { \
DATA_TRANSFER(__transfer, __item); \
STRNCPY(_row->createby, __transfer->mvalue); \
} \
__item = optional_name(_root, "createcode", 1, NULL, __reply, __siz); \
__item = optional_name(_root, CODETRF, 1, NULL, __reply, __siz); \
if (__item) { \
DATA_TRANSFER(__transfer, __item); \
STRNCPY(_row->createcode, __transfer->mvalue); \
} \
__item = optional_name(_root, "createinet", 1, NULL, __reply, __siz); \
__item = optional_name(_root, INETTRF, 1, NULL, __reply, __siz); \
if (__item) { \
DATA_TRANSFER(__transfer, __item); \
STRNCPY(_row->createinet, __transfer->mvalue); \
@ -751,6 +774,172 @@ extern K_ITEM shareerrors_secondaryuserid;
extern tv_t missing_secuser_min;
extern tv_t missing_secuser_max;
/* The aim of the sequence data is to identify and ignore duplicate records -
* which should usually only be during a reload -
* and to identify missing records when their sequence numbers are skipped
*
* If at any time there is a problem with a sequence number, an error is
* reported, then the record being processed is simply processed normally by
* the cmd_func() it was intended for - which may or may not produce other
* processing error messages depending on the validity of the rest of the data
*
* Field explanation:
* Normal sequence processing would be that we first get seq N, then N+1
* then N+2 ... etc.
* seqbase,minseq,maxseq are all set to the first N for the given sequence
* maxseq is incremented to the current maximum N+x each time a record is
* processed
* If we get up to N+3 but it is unexpectedly followed by N+5, that means N+4
* is currently missing - so it is flagged as missing by MISSFLAG=0 and the
* missing counters are incremented - maxseq will now be N+5
* Once we reach N+size we need to discard N and use it as N+size
* and increment seqbase N
* When we discard the oldest item due to needing more, if that oldest
* item was missing, it is now considered lost and the lost counters
* are incremented (and missing counters decremented)
* If we receive an item N+x where N+x-maxseq>highlimit we reject it as high
* and increment the high counters - this avoids creating a high bad sequence
* number and flagging any missing sequence numbers, most likely incorrectly,
* as lost in the range N to N+x-size
* If we receive an item N-x i.e. less than seqbase N, then:
* If maxseq-N = size then N-x is considered stale and the stale counters
* are incremented since there's no unused items below N available
* This shouldn't normally happen after we've received size seq numbers
* Else maxseq-N is less than size, that means there are unused items below N
* This will usually only be with a new sequence and the first seq was out
* of order, before lower sequence numbers, thus maxseq should be close to
* seqbase N and no where near N+size and there should be x unused below N
* If there are x unused items below N then we can move seqbase down to N-x
* after we flag all N-1,N-2,N-3..N-(x-1) as missing
* Else there aren't enough unused items below N, then N-x is considered
* stale and the stale counters are incremented
*
* timelimit is an early limit to flag missing sequence numbers as 'transient'
* Normally, if a missing item at N is later reused, it will be discarded and
* reported as lost
* After the reload queue is complete, timelimit reports missing sequence
* numbers early, as transient, if they have been missing for 'timelimit' but
* not already lost
* missing isn't decremented, since it is still treated as missing
* This is needed in case a size limit on a sequence means it may take a long
* time before it reports messages as lost - this also means that after the
* reload queue has cleared after ckdb startup, it will report the transient
* missing sequence numbers shortly after the timelimit
* When they are later found or lost they will again be reported, this time as
* found or lost */
// ckpool sequence numbers
#define SEQALL "seqall"
#define SEQSTT "seqstart"
#define SEQPID "seqpid"
#define SEQPRE "seq"
/* Value to use for SEQSTT when manually sending messages,
* to make ckdb not check the seq numbers
* The message must have a SEQALL but the value is ignored
* SEQPID and SEQcmd don't need to exist and are ignored */
#define SEQSTTIGN 42
enum seq_num {
SEQ_NONE = -1, // Invalid to have ckpool seq numbers
SEQ_ALL,
SEQ_BLOCK,
SEQ_SHARES,
SEQ_WORKINFO,
SEQ_AGEWORKINFO,
SEQ_AUTH,
SEQ_ADDRAUTH,
SEQ_HEARTBEAT,
SEQ_SHAREERRORS,
SEQ_WORKERSTAT,
SEQ_POOLSTATS,
SEQ_MAX
};
// Ensure size is a (multiple of 8)-1
#define SEQ_CODE 15
typedef struct seqitem {
tv_t cd; // sec:0=missing, usec:0=miss !0=trans
tv_t time;
char code[SEQ_CODE+1];
} SEQITEM;
typedef struct seqdata {
size_t size; // item count - MUST be a power of 2
uint64_t highlimit;
int timelimit;
uint64_t minseq;
uint64_t maxseq;
uint64_t seqbase;
uint64_t missing;
uint64_t trans;
uint64_t lost;
uint64_t stale;
uint64_t high;
uint64_t ok;
tv_t firsttime;
tv_t lasttime;
tv_t firstcd;
tv_t lastcd;
SEQITEM *item;
} SEQDATA;
// SEQSET
typedef struct seqset {
uint64_t seqstt; // 0 if unused/unallocated
uint64_t seqpid;
uint64_t missing; // total from seqdata
uint64_t trans; // total from seqdata
uint64_t lost; // total from seqdata
uint64_t stale; // total from seqdata
uint64_t high; // total from seqdata
uint64_t ok; // total from seqdata
SEQDATA seqdata[SEQ_MAX];
} SEQSET;
/* All *_SIZ must be >= 64 and a power of 2
* but if any aren't, the code checks this and quit()s
* the first time it processes a record with sequences */
// SEQALL and SHARES */
#define SEQ_LARGE_LIM 64
#define SEQ_LARGE_SIZ (65536*SEQ_LARGE_LIM)
// WORKERSTATS, AUTH and ADDRAUTH
#define SEQ_MEDIUM_LIM 128
#define SEQ_MEDIUM_SIZ 65536
// The rest
#define SEQ_SMALL_LIM 128
#define SEQ_SMALL_SIZ 16384
#define ALLOC_SEQSET 1
#define LIMIT_SEQSET 16
#define INIT_SEQSET(_item) INIT_GENERIC(_item, seqset)
#define DATA_SEQSET(_var, _item) DATA_GENERIC(_var, _item, seqset, true)
extern K_LIST *seqset_free;
// each new seqset is added to the head, so head is the current one
extern K_STORE *seqset_store;
// Initialised when seqset_free is allocated
extern char *seqnam[SEQ_MAX];
// SEQTRANS
typedef struct seqtrans {
int seq;
uint64_t seqnum;
SEQITEM item;
} SEQTRANS;
// The stores are created and freed each time required
extern K_LIST *seqtrans_free;
#define ALLOC_SEQTRANS 1024
#define LIMIT_SEQTRANS 0
#define CULL_SEQTRANS 65536
#define INIT_SEQTRANS(_item) INIT_GENERIC(_item, seqtrans)
#define DATA_SEQTRANS(_var, _item) DATA_GENERIC(_var, _item, seqtrans, true)
// USERS
typedef struct users {
int64_t userid;
@ -1701,8 +1890,11 @@ extern void free_optioncontrol_data(K_ITEM *item);
extern void free_markersummary_data(K_ITEM *item);
extern void free_workmarkers_data(K_ITEM *item);
extern void free_marks_data(K_ITEM *item);
extern void free_seqset_data(K_ITEM *item);
extern char *safe_text(char *txt);
#define safe_text(_txt) _safe_text(_txt, true)
#define safe_text_nonull(_txt) _safe_text(_txt, false)
extern char *_safe_text(char *txt, bool shownull);
extern void username_trim(USERS *users);
extern bool like_address(char *username);
@ -1738,6 +1930,9 @@ extern char *_data_to_buf(enum data_type typ, void *data, char *buf, size_t siz,
#define btv_to_buf(_data, _buf, _siz) _btv_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 t_to_buf(_data, _buf, _siz) _t_to_buf(_data, _buf, _siz, WHERE_FFL_HERE)
#define bt_to_buf(_data, _buf, _siz) _bt_to_buf(_data, _buf, _siz, WHERE_FFL_HERE)
#define btu64_to_buf(_data, _buf, _siz) _btu64_to_buf(_data, _buf, _siz, WHERE_FFL_HERE)
extern char *_str_to_buf(char data[], char *buf, size_t siz, WHERE_FFL_ARGS);
extern char *_bigint_to_buf(int64_t data, char *buf, size_t siz, WHERE_FFL_ARGS);
@ -1749,12 +1944,17 @@ extern char *_ctv_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS);
extern char *_ftv_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS);
// Convert tv to seconds (ignore uS)
extern char *_tvs_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS);
// Convert tv to (brief) DD HH:MM:SS
// Convert tv to (brief) DD/HH:MM:SS
extern char *_btv_to_buf(tv_t *data, char *buf, size_t siz, WHERE_FFL_ARGS);
/* unused yet
extern char *_blob_to_buf(char *data, char *buf, size_t siz, WHERE_FFL_ARGS);
*/
extern char *_double_to_buf(double data, char *buf, size_t siz, WHERE_FFL_ARGS);
// Convert seconds (only) time to date
extern char *_t_to_buf(time_t *data, char *buf, size_t siz, WHERE_FFL_ARGS);
// Convert seconds (only) time to (brief) M-DD/HH:MM:SS
extern char *_bt_to_buf(time_t *data, char *buf, size_t siz, WHERE_FFL_ARGS);
extern char *_btu64_to_buf(uint64_t *data, char *buf, size_t siz, WHERE_FFL_ARGS);
extern char *_transfer_data(K_ITEM *item, WHERE_FFL_ARGS);
extern void dsp_transfer(K_ITEM *item, FILE *stream);
@ -2131,6 +2331,7 @@ struct CMDS {
bool createdate; // requires a createdate
char *(*func)(PGconn *, char *, char *, tv_t *, char *, char *,
char *, tv_t *, K_TREE *);
enum seq_num seq;
char *access;
};

102
src/ckdb_cmd.c

@ -945,12 +945,12 @@ redo:
APPEND_REALLOC(buf, off, len, tmp);
snprintf(tmp, sizeof(tmp),
"firstcreatedate:%d=%ld%c", rows,
"first"CDTRF":%d=%ld%c", rows,
first_cd.tv_sec, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
snprintf(tmp, sizeof(tmp),
"createdate:%d=%ld%c", rows,
CDTRF":%d=%ld%c", rows,
blocks->createdate.tv_sec, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
@ -1077,8 +1077,8 @@ redo:
snprintf(tmp, sizeof(tmp),
"rows=%d%cflds=%s%c",
rows, FLDSEP,
"seq,height,blockhash,nonce,reward,workername,firstcreatedate,"
"createdate,status,statsconf,diffacc,diffinv,shareacc,"
"seq,height,blockhash,nonce,reward,workername,first"CDTRF","
CDTRF",status,statsconf,diffacc,diffinv,shareacc,"
"shareinv,elapsed,netdiff,diffratio,cdf,luck", FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
@ -2683,7 +2683,7 @@ static char *cmd_heartbeat(__maybe_unused PGconn *conn, char *cmd, char *id,
snprintf(tmp, sizeof(tmp),
"%s{\"workername\":\"%s\","
"\"difficultydefault\":%d,"
"\"createdate\":\"%ld,%ld\"}",
"\""CDTRF"\":\"%ld,%ld\"}",
first ? "" : ",",
heartbeatqueue->workername,
heartbeatqueue->difficultydefault,
@ -5198,6 +5198,8 @@ static char *cmd_stats(__maybe_unused PGconn *conn, char *cmd, char *id,
USEINFO(transfer, 0, 0);
USEINFO(heartbeatqueue, 1, 0);
USEINFO(logqueue, 1, 0);
USEINFO(seqset, 1, 0);
USEINFO(seqtrans, 0, 0);
snprintf(tmp, sizeof(tmp), "totalram=%"PRIu64"%c", tot, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
@ -5908,50 +5910,50 @@ static char *cmd_pshift(__maybe_unused PGconn *conn, char *cmd, char *id,
* For the heartbeat pulse reply it has no '={}'
*/
// cmd_val cmd_str noid createdate func access
// cmd_val cmd_str noid createdate func seq access
struct CMDS ckdb_cmds[] = {
{ CMD_TERMINATE, "terminate", true, false, NULL, ACCESS_SYSTEM },
{ CMD_PING, "ping", true, false, NULL, ACCESS_SYSTEM ACCESS_POOL ACCESS_WEB },
{ CMD_VERSION, "version", true, false, NULL, ACCESS_SYSTEM ACCESS_POOL ACCESS_WEB },
{ CMD_LOGLEVEL, "loglevel", true, false, NULL, ACCESS_SYSTEM },
{ CMD_FLUSH, "flush", true, false, NULL, ACCESS_SYSTEM },
{ CMD_SHARELOG, STR_WORKINFO, false, true, cmd_sharelog, ACCESS_POOL },
{ CMD_SHARELOG, STR_SHARES, false, true, cmd_sharelog, ACCESS_POOL },
{ CMD_SHARELOG, STR_SHAREERRORS, false, true, cmd_sharelog, ACCESS_POOL },
{ CMD_SHARELOG, STR_AGEWORKINFO, false, true, cmd_sharelog, ACCESS_POOL },
{ CMD_AUTH, "authorise", false, true, cmd_auth, ACCESS_POOL },
{ CMD_ADDRAUTH, "addrauth", false, true, cmd_addrauth, ACCESS_POOL },
{ CMD_HEARTBEAT,"heartbeat", false, true, cmd_heartbeat, ACCESS_POOL },
{ CMD_ADDUSER, "adduser", false, false, cmd_adduser, ACCESS_WEB },
{ CMD_NEWPASS, "newpass", false, false, cmd_newpass, ACCESS_WEB },
{ CMD_CHKPASS, "chkpass", false, false, cmd_chkpass, ACCESS_WEB },
{ CMD_USERSET, "usersettings", false, false, cmd_userset, ACCESS_WEB },
{ CMD_WORKERSET,"workerset", false, false, cmd_workerset, ACCESS_WEB },
{ CMD_POOLSTAT, "poolstats", false, true, cmd_poolstats, ACCESS_POOL },
{ CMD_USERSTAT, "userstats", false, true, cmd_userstats, ACCESS_POOL },
{ CMD_WORKERSTAT,"workerstats", false, true, cmd_workerstats,ACCESS_POOL },
{ CMD_BLOCK, "block", false, true, cmd_blocks, ACCESS_POOL },
{ CMD_BLOCKLIST,"blocklist", false, false, cmd_blocklist, ACCESS_WEB },
{ CMD_BLOCKSTATUS,"blockstatus",false, false, cmd_blockstatus,ACCESS_SYSTEM },
{ CMD_NEWID, "newid", false, false, cmd_newid, ACCESS_SYSTEM },
{ CMD_PAYMENTS, "payments", false, false, cmd_payments, ACCESS_WEB },
{ CMD_WORKERS, "workers", false, false, cmd_workers, ACCESS_WEB },
{ CMD_ALLUSERS, "allusers", false, false, cmd_allusers, ACCESS_WEB },
{ CMD_HOMEPAGE, "homepage", false, false, cmd_homepage, ACCESS_WEB },
{ CMD_GETATTS, "getatts", false, false, cmd_getatts, ACCESS_WEB },
{ CMD_SETATTS, "setatts", false, false, cmd_setatts, ACCESS_WEB },
{ CMD_EXPATTS, "expatts", false, false, cmd_expatts, ACCESS_WEB },
{ CMD_GETOPTS, "getopts", false, false, cmd_getopts, ACCESS_WEB },
{ CMD_SETOPTS, "setopts", false, false, cmd_setopts, ACCESS_WEB },
{ CMD_DSP, "dsp", false, false, cmd_dsp, ACCESS_SYSTEM },
{ CMD_STATS, "stats", true, false, cmd_stats, ACCESS_SYSTEM ACCESS_WEB },
{ CMD_PPLNS, "pplns", false, false, cmd_pplns, ACCESS_SYSTEM ACCESS_WEB },
{ CMD_PPLNS2, "pplns2", false, false, cmd_pplns2, ACCESS_SYSTEM ACCESS_WEB },
{ CMD_PAYOUTS, "payouts", false, false, cmd_payouts, ACCESS_SYSTEM },
{ CMD_MPAYOUTS, "mpayouts", false, false, cmd_mpayouts, ACCESS_SYSTEM ACCESS_WEB },
{ CMD_SHIFTS, "shifts", false, false, cmd_shifts, ACCESS_SYSTEM ACCESS_WEB },
{ CMD_USERSTATUS,"userstatus", false, false, cmd_userstatus, ACCESS_SYSTEM ACCESS_WEB },
{ CMD_MARKS, "marks", false, false, cmd_marks, ACCESS_SYSTEM },
{ CMD_PSHIFT, "pshift", false, false, cmd_pshift, ACCESS_SYSTEM ACCESS_WEB },
{ CMD_END, NULL, false, false, NULL, NULL }
{ CMD_TERMINATE, "terminate", true, false, NULL, SEQ_NONE, ACCESS_SYSTEM },
{ CMD_PING, "ping", true, false, NULL, SEQ_NONE, ACCESS_SYSTEM ACCESS_POOL ACCESS_WEB },
{ CMD_VERSION, "version", true, false, NULL, SEQ_NONE, ACCESS_SYSTEM ACCESS_POOL ACCESS_WEB },
{ CMD_LOGLEVEL, "loglevel", true, false, NULL, SEQ_NONE, ACCESS_SYSTEM },
{ CMD_FLUSH, "flush", true, false, NULL, SEQ_NONE, ACCESS_SYSTEM },
{ CMD_SHARELOG, STR_WORKINFO, false, true, cmd_sharelog, SEQ_WORKINFO, ACCESS_POOL },
{ CMD_SHARELOG, STR_SHARES, false, true, cmd_sharelog, SEQ_SHARES, ACCESS_POOL },
{ CMD_SHARELOG, STR_SHAREERRORS,false, true, cmd_sharelog, SEQ_SHAREERRORS,ACCESS_POOL },
{ CMD_SHARELOG, STR_AGEWORKINFO,false, true, cmd_sharelog, SEQ_AGEWORKINFO,ACCESS_POOL },
{ CMD_AUTH, "authorise", false, true, cmd_auth, SEQ_AUTH, ACCESS_POOL },
{ CMD_ADDRAUTH, "addrauth", false, true, cmd_addrauth, SEQ_ADDRAUTH, ACCESS_POOL },
{ CMD_HEARTBEAT,"heartbeat", false, true, cmd_heartbeat, SEQ_HEARTBEAT, ACCESS_POOL },
{ CMD_ADDUSER, "adduser", false, false, cmd_adduser, SEQ_NONE, ACCESS_WEB },
{ CMD_NEWPASS, "newpass", false, false, cmd_newpass, SEQ_NONE, ACCESS_WEB },
{ CMD_CHKPASS, "chkpass", false, false, cmd_chkpass, SEQ_NONE, ACCESS_WEB },
{ CMD_USERSET, "usersettings", false, false, cmd_userset, SEQ_NONE, ACCESS_WEB },
{ CMD_WORKERSET,"workerset", false, false, cmd_workerset, SEQ_NONE, ACCESS_WEB },
{ CMD_POOLSTAT, "poolstats", false, true, cmd_poolstats, SEQ_POOLSTATS, ACCESS_POOL },
{ CMD_USERSTAT, "userstats", false, true, cmd_userstats, SEQ_NONE, ACCESS_POOL },
{ CMD_WORKERSTAT,"workerstats", false, true, cmd_workerstats,SEQ_WORKERSTAT, ACCESS_POOL },
{ CMD_BLOCK, "block", false, true, cmd_blocks, SEQ_BLOCK, ACCESS_POOL },
{ CMD_BLOCKLIST,"blocklist", false, false, cmd_blocklist, SEQ_NONE, ACCESS_WEB },
{ CMD_BLOCKSTATUS,"blockstatus",false, false, cmd_blockstatus,SEQ_NONE, ACCESS_SYSTEM },
{ CMD_NEWID, "newid", false, false, cmd_newid, SEQ_NONE, ACCESS_SYSTEM },
{ CMD_PAYMENTS, "payments", false, false, cmd_payments, SEQ_NONE, ACCESS_WEB },
{ CMD_WORKERS, "workers", false, false, cmd_workers, SEQ_NONE, ACCESS_WEB },
{ CMD_ALLUSERS, "allusers", false, false, cmd_allusers, SEQ_NONE, ACCESS_WEB },
{ CMD_HOMEPAGE, "homepage", false, false, cmd_homepage, SEQ_NONE, ACCESS_WEB },
{ CMD_GETATTS, "getatts", false, false, cmd_getatts, SEQ_NONE, ACCESS_WEB },
{ CMD_SETATTS, "setatts", false, false, cmd_setatts, SEQ_NONE, ACCESS_WEB },
{ CMD_EXPATTS, "expatts", false, false, cmd_expatts, SEQ_NONE, ACCESS_WEB },
{ CMD_GETOPTS, "getopts", false, false, cmd_getopts, SEQ_NONE, ACCESS_WEB },
{ CMD_SETOPTS, "setopts", false, false, cmd_setopts, SEQ_NONE, ACCESS_WEB },
{ CMD_DSP, "dsp", false, false, cmd_dsp, SEQ_NONE, ACCESS_SYSTEM },
{ CMD_STATS, "stats", true, false, cmd_stats, SEQ_NONE, ACCESS_SYSTEM ACCESS_WEB },
{ CMD_PPLNS, "pplns", false, false, cmd_pplns, SEQ_NONE, ACCESS_SYSTEM ACCESS_WEB },
{ CMD_PPLNS2, "pplns2", false, false, cmd_pplns2, SEQ_NONE, ACCESS_SYSTEM ACCESS_WEB },
{ CMD_PAYOUTS, "payouts", false, false, cmd_payouts, SEQ_NONE, ACCESS_SYSTEM },
{ CMD_MPAYOUTS, "mpayouts", false, false, cmd_mpayouts, SEQ_NONE, ACCESS_SYSTEM ACCESS_WEB },
{ CMD_SHIFTS, "shifts", false, false, cmd_shifts, SEQ_NONE, ACCESS_SYSTEM ACCESS_WEB },
{ CMD_USERSTATUS,"userstatus", false, false, cmd_userstatus, SEQ_NONE, ACCESS_SYSTEM ACCESS_WEB },
{ CMD_MARKS, "marks", false, false, cmd_marks, SEQ_NONE, ACCESS_SYSTEM },
{ CMD_PSHIFT, "pshift", false, false, cmd_pshift, SEQ_NONE, ACCESS_SYSTEM ACCESS_WEB },
{ CMD_END, NULL, false, false, NULL, SEQ_NONE, NULL }
};

59
src/ckdb_data.c

@ -87,8 +87,21 @@ void free_marks_data(K_ITEM *item)
FREENULL(marks->extra);
}
void free_seqset_data(K_ITEM *item)
{
SEQSET *seqset;
int i;
DATA_SEQSET(seqset, item);
if (seqset->seqstt) {
for (i = 0; i < SEQ_MAX; i++)
FREENULL(seqset->seqdata[i].item);
seqset->seqstt = 0;
}
}
// Clear text printable version of txt up to first '\0'
char *safe_text(char *txt)
char *_safe_text(char *txt, bool shownull)
{
unsigned char *ptr = (unsigned char *)txt;
size_t len;
@ -114,7 +127,11 @@ char *safe_text(char *txt)
buf += 4;
}
}
strcpy(buf, "0x00");
if (shownull)
strcpy(buf, "0x00");
else
*buf = '\0';
return ret;
}
@ -375,6 +392,9 @@ char *_data_to_buf(enum data_type typ, void *data, char *buf, size_t siz, WHERE_
break;
case TYPE_TV:
case TYPE_TVS:
case TYPE_BTV:
case TYPE_T:
case TYPE_BT:
siz = DATE_BUFSIZ;
break;
case TYPE_CTV:
@ -441,6 +461,25 @@ char *_data_to_buf(enum data_type typ, void *data, char *buf, size_t siz, WHERE_
case TYPE_DOUBLE:
snprintf(buf, siz, "%f", *((double *)data));
break;
case TYPE_T:
gmtime_r((time_t *)data, &tm);
snprintf(buf, siz, "%d-%02d-%02d %02d:%02d:%02d+00",
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec);
break;
case TYPE_BT:
gmtime_r((time_t *)data, &tm);
snprintf(buf, siz, "%d-%02d %02d:%02d:%02d",
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec);
break;
}
return buf;
@ -502,6 +541,22 @@ char *_double_to_buf(double data, char *buf, size_t siz, WHERE_FFL_ARGS)
return _data_to_buf(TYPE_DOUBLE, (void *)(&data), buf, siz, WHERE_FFL_PASS);
}
char *_t_to_buf(time_t *data, char *buf, size_t siz, WHERE_FFL_ARGS)
{
return _data_to_buf(TYPE_T, (void *)data, buf, siz, WHERE_FFL_PASS);
}
char *_bt_to_buf(time_t *data, char *buf, size_t siz, WHERE_FFL_ARGS)
{
return _data_to_buf(TYPE_BT, (void *)data, buf, siz, WHERE_FFL_PASS);
}
char *_btu64_to_buf(uint64_t *data, char *buf, size_t siz, WHERE_FFL_ARGS)
{
time_t t = *data;
return _data_to_buf(TYPE_BT, (void *)&t, buf, siz, WHERE_FFL_PASS);
}
// For mutiple variable function calls that need the data
char *_transfer_data(K_ITEM *item, WHERE_FFL_ARGS)
{

182
src/ckdb_dbio.c

@ -37,26 +37,26 @@ char *pqerrmsg(PGconn *conn)
// HISTORY FIELDS
#define HISTORYDATEFLDS(_res, _row, _data, _ok) do { \
char *_fld; \
PQ_GET_FLD(_res, _row, "createdate", _fld, _ok); \
PQ_GET_FLD(_res, _row, CDDB, _fld, _ok); \
if (!_ok) \
break; \
TXT_TO_TV("createdate", _fld, (_data)->createdate); \
PQ_GET_FLD(_res, _row, "createby", _fld, _ok); \
TXT_TO_TV(CDDB, _fld, (_data)->createdate); \
PQ_GET_FLD(_res, _row, BYDB, _fld, _ok); \
if (!_ok) \
break; \
TXT_TO_STR("createby", _fld, (_data)->createby); \
PQ_GET_FLD(_res, _row, "createcode", _fld, _ok); \
TXT_TO_STR(BYDB, _fld, (_data)->createby); \
PQ_GET_FLD(_res, _row, CODEDB, _fld, _ok); \
if (!_ok) \
break; \
TXT_TO_STR("createcode", _fld, (_data)->createcode); \
PQ_GET_FLD(_res, _row, "createinet", _fld, _ok); \
TXT_TO_STR(CODEDB, _fld, (_data)->createcode); \
PQ_GET_FLD(_res, _row, INETDB, _fld, _ok); \
if (!_ok) \
break; \
TXT_TO_STR("createinet", _fld, (_data)->createinet); \
PQ_GET_FLD(_res, _row, "expirydate", _fld, _ok); \
TXT_TO_STR(INETDB, _fld, (_data)->createinet); \
PQ_GET_FLD(_res, _row, EDDB, _fld, _ok); \
if (!_ok) \
break; \
TXT_TO_TV("expirydate", _fld, (_data)->expirydate); \
TXT_TO_TV(EDDB, _fld, (_data)->expirydate); \
} while (0)
#define HISTORYDATEPARAMS(_params, _his_pos, _row) do { \
@ -70,35 +70,35 @@ char *pqerrmsg(PGconn *conn)
// MODIFY FIELDS
#define MODIFYDATEFLDPOINTERS(_list, _res, _row, _data, _ok) do { \
char *_fld; \
PQ_GET_FLD(_res, _row, "createdate", _fld, _ok); \
PQ_GET_FLD(_res, _row, CDDB, _fld, _ok); \
if (!_ok) \
break; \
TXT_TO_TV("createdate", _fld, (_data)->createdate); \
PQ_GET_FLD(_res, _row, "createby", _fld, _ok); \
TXT_TO_TV(CDDB, _fld, (_data)->createdate); \
PQ_GET_FLD(_res, _row, BYDB, _fld, _ok); \
if (!_ok) \
break; \
SET_CREATEBY(_list, (_data)->createby, _fld); \
PQ_GET_FLD(_res, _row, "createcode", _fld, _ok); \
PQ_GET_FLD(_res, _row, CODEDB, _fld, _ok); \
if (!_ok) \
break; \
SET_CREATECODE(_list, (_data)->createcode, _fld); \
PQ_GET_FLD(_res, _row, "createinet", _fld, _ok); \
PQ_GET_FLD(_res, _row, INETDB, _fld, _ok); \
if (!_ok) \
break; \
SET_CREATEINET(_list, (_data)->createinet, _fld); \
PQ_GET_FLD(_res, _row, "modifydate", _fld, _ok); \
PQ_GET_FLD(_res, _row, MDDB, _fld, _ok); \
if (!_ok) \
break; \
TXT_TO_TV("modifydate", _fld, (_data)->modifydate); \
PQ_GET_FLD(_res, _row, "modifyby", _fld, _ok); \
TXT_TO_TV(MDDB, _fld, (_data)->modifydate); \
PQ_GET_FLD(_res, _row, MBYDB, _fld, _ok); \
if (!_ok) \
break; \
SET_MODIFYBY(_list, (_data)->modifyby, _fld); \
PQ_GET_FLD(_res, _row, "modifycode", _fld, _ok); \
PQ_GET_FLD(_res, _row, MCODEDB, _fld, _ok); \
if (!_ok) \
break; \
SET_MODIFYCODE(_list, (_data)->modifycode, _fld); \
PQ_GET_FLD(_res, _row, "modifyinet", _fld, _ok); \
PQ_GET_FLD(_res, _row, MINETDB, _fld, _ok); \
if (!_ok) \
break; \
SET_MODIFYINET(_list, (_data)->modifyinet, _fld); \
@ -125,22 +125,22 @@ char *pqerrmsg(PGconn *conn)
// SIMPLE FIELDS
#define SIMPLEDATEFLDS(_res, _row, _data, _ok) do { \
char *_fld; \
PQ_GET_FLD(_res, _row, "createdate", _fld, _ok); \
PQ_GET_FLD(_res, _row, CDDB, _fld, _ok); \
if (!_ok) \
break; \
TXT_TO_TV("createdate", _fld, (_data)->createdate); \
PQ_GET_FLD(_res, _row, "createby", _fld, _ok); \
TXT_TO_TV(CDDB, _fld, (_data)->createdate); \
PQ_GET_FLD(_res, _row, BYDB, _fld, _ok); \
if (!_ok) \
break; \
TXT_TO_STR("createby", _fld, (_data)->createby); \
PQ_GET_FLD(_res, _row, "createcode", _fld, _ok); \
TXT_TO_STR(BYDB, _fld, (_data)->createby); \
PQ_GET_FLD(_res, _row, CODEDB, _fld, _ok); \
if (!_ok) \
break; \
TXT_TO_STR("createcode", _fld, (_data)->createcode); \
PQ_GET_FLD(_res, _row, "createinet", _fld, _ok); \
TXT_TO_STR(CODEDB, _fld, (_data)->createcode); \
PQ_GET_FLD(_res, _row, INETDB, _fld, _ok); \
if (!_ok) \
break; \
TXT_TO_STR("createinet", _fld, (_data)->createinet); \
TXT_TO_STR(INETDB, _fld, (_data)->createinet); \
} while (0)
#define SIMPLEDATEPARAMS(_params, _his_pos, _row) do { \
@ -342,8 +342,8 @@ int64_t nextid(PGconn *conn, char *idname, int64_t increment,
lastid += increment;
snprintf(qry, sizeof(qry), "update idcontrol set "
"lastid=$1, modifydate=$2, modifyby=$3, "
"modifycode=$4, modifyinet=$5 "
"lastid=$1,"MDDB"=$2,"MBYDB"=$3,"
MCODEDB"=$4,"MINETDB"=$5 "
"where idname='%s'",
idname);
@ -421,7 +421,7 @@ bool users_update(PGconn *conn, K_ITEM *u_item, char *oldhash,
HISTORYDATEINIT(row, cd, by, code, inet);
HISTORYDATETRANSFER(trf_root, row);
upd = "update users set expirydate=$1 where userid=$2 and expirydate=$3";
upd = "update users set "EDDB"=$1 where userid=$2 and "EDDB"=$3";
par = 0;
params[par++] = tv_to_buf(cd, NULL, 0);
params[par++] = bigint_to_buf(row->userid, NULL, 0);
@ -472,7 +472,7 @@ bool users_update(PGconn *conn, K_ITEM *u_item, char *oldhash,
"userid,username,$3,$4,joineddate,"
"$5,secondaryuserid,$6,"
"$7,$8,$9,$10,$11 from users where "
"userid=$1 and expirydate=$2";
"userid=$1 and "EDDB"=$2";
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0, CKPQ_WRITE);
rescode = PQresultStatus(res);
@ -795,8 +795,8 @@ bool useratts_item_add(PGconn *conn, K_ITEM *ua_item, tv_t *cd, bool begun)
}
if (old_item) {
upd = "update useratts set expirydate=$1 where userid=$2 and "
"attname=$3 and expirydate=$4";
upd = "update useratts set "EDDB"=$1 where userid=$2 and "
"attname=$3 and "EDDB"=$4";
par = 0;
params[par++] = tv_to_buf(cd, NULL, 0);
params[par++] = bigint_to_buf(old_useratts->userid, NULL, 0);
@ -901,7 +901,7 @@ K_ITEM *useratts_add(PGconn *conn, char *username, char *attname,
if (!u_item) {
LOGERR("%s(): unknown user '%s'",
__func__,
st = safe_text(username));
st = safe_text_nonull(username));
FREENULL(st);
goto unitem;
}
@ -985,8 +985,8 @@ bool useratts_item_expire(PGconn *conn, K_ITEM *ua_item, tv_t *cd)
conned = true;
}
upd = "update useratts set expirydate=$1 where userid=$2 and "
"attname=$3 and expirydate=$4";
upd = "update useratts set "EDDB"=$1 where userid=$2 and "
"attname=$3 and "EDDB"=$4";
par = 0;
params[par++] = tv_to_buf(cd, NULL, 0);
params[par++] = bigint_to_buf(useratts->userid, NULL, 0);
@ -1327,7 +1327,7 @@ bool workers_update(PGconn *conn, K_ITEM *item, char *difficultydefault,
HISTORYDATEINIT(row, cd, by, code, inet);
HISTORYDATETRANSFER(trf_root, row);
upd = "update workers set expirydate=$1 where workerid=$2 and expirydate=$3";
upd = "update workers set "EDDB"=$1 where workerid=$2 and "EDDB"=$3";
par = 0;
params[par++] = tv_to_buf(cd, NULL, 0);
params[par++] = bigint_to_buf(row->workerid, NULL, 0);
@ -1551,8 +1551,8 @@ bool paymentaddresses_set(PGconn *conn, int64_t userid, K_STORE *pa_store,
count = matches = 0;
APPEND_REALLOC_INIT(upd, off, len);
APPEND_REALLOC(upd, off, len,
"update paymentaddresses set expirydate=$1 where "
"userid=$2 and expirydate=$3 and payaddress in (");
"update paymentaddresses set "EDDB"=$1 where "
"userid=$2 and "EDDB"=$3 and payaddress in (");
par = 0;
params[par++] = tv_to_buf(cd, NULL, 0);
params[par++] = bigint_to_buf(userid, NULL, 0);
@ -1905,8 +1905,8 @@ bool payments_add(PGconn *conn, bool add, K_ITEM *p_item, K_ITEM **old_p_item,
DATA_PAYMENTS(oldp, *old_p_item);
upd = "update payments set expirydate=$1 where paymentid=$2"
" and expirydate=$3";
upd = "update payments set "EDDB"=$1 where paymentid=$2"
" and "EDDB"=$3";
par = 0;
params[par++] = tv_to_buf(cd, NULL, 0);
params[par++] = bigint_to_buf(oldp->paymentid, NULL, 0);
@ -2220,9 +2220,9 @@ K_ITEM *optioncontrol_item_add(PGconn *conn, K_ITEM *oc_item, tv_t *cd, bool beg
if (old_item) {
upd = "update optioncontrol "
"set expirydate=$1 where optionname=$2 and "
"set "EDDB"=$1 where optionname=$2 and "
"activationdate=$3 and activationheight=$4 and "
"expirydate=$5";
EDDB"=$5";
par = 0;
params[par++] = tv_to_buf(cd, NULL, 0);
@ -2367,7 +2367,7 @@ bool optioncontrol_fill(PGconn *conn)
sel = "select "
"optionname,optionvalue,activationdate,activationheight"
HISTORYDATECONTROL
" from optioncontrol where expirydate=$1";
" from optioncontrol where "EDDB"=$1";
par = 0;
params[par++] = tv_to_buf((tv_t *)(&default_expiry), NULL, 0);
PARCHK(par, params);
@ -2635,7 +2635,7 @@ bool workinfo_fill(PGconn *conn)
"workinfoid,poolinstance,merklehash,prevhash,"
"coinbase1,coinbase2,version,bits,ntime,reward"
HISTORYDATECONTROL
" from workinfo where expirydate=$1 and"
" from workinfo where "EDDB"=$1 and"
" ((workinfoid>=$2 and workinfoid<=$3)");
// If we aren't loading the full range, ensure the necessary ones are loaded
@ -2797,7 +2797,7 @@ static bool shares_process(PGconn *conn, SHARES *shares, K_TREE *trf_root)
if (!w_item) {
LOGDEBUG("%s(): new_default_worker failed %"PRId64"/%s/%ld,%ld",
__func__, shares->userid,
st = safe_text(shares->workername),
st = safe_text_nonull(shares->workername),
shares->createdate.tv_sec, shares->createdate.tv_usec);
FREENULL(st);
return false;
@ -2811,7 +2811,7 @@ static bool shares_process(PGconn *conn, SHARES *shares, K_TREE *trf_root)
LOGDEBUG("%s(): workmarker exists for wid %"PRId64
" %"PRId64"/%s/%ld,%ld",
__func__, shares->workinfoid, shares->userid,
st = safe_text(shares->workername),
st = safe_text_nonull(shares->workername),
shares->createdate.tv_sec,
shares->createdate.tv_usec);
FREENULL(st);
@ -2827,7 +2827,7 @@ static bool shares_process(PGconn *conn, SHARES *shares, K_TREE *trf_root)
"%"PRId64" %"PRId64"/%s/%ld,%ld",
__func__, sharesummary->complete,
shares->workinfoid, shares->userid,
st = safe_text(shares->workername),
st = safe_text_nonull(shares->workername),
shares->createdate.tv_sec,
shares->createdate.tv_usec);
FREENULL(st);
@ -2938,7 +2938,7 @@ keep:
LOGERR("%s() %"PRId64"/%s/%ld,%ld %s/%"PRId32"/%"PRId32
" Early share procured",
__func__, early_shares->workinfoid,
st = safe_text(early_shares->workername),
st = safe_text_nonull(early_shares->workername),
early_shares->createdate.tv_sec,
early_shares->createdate.tv_usec, cd_buf,
early_shares->oldcount, early_shares->redo);
@ -2953,7 +2953,7 @@ discard:
LOGERR("%s() %"PRId64"/%s/%ld,%ld %s/%"PRId32"/%"PRId32
" Early share discarded!%s",
__func__, early_shares->workinfoid,
st = safe_text(early_shares->workername),
st = safe_text_nonull(early_shares->workername),
early_shares->createdate.tv_sec,
early_shares->createdate.tv_usec, cd_buf,
early_shares->oldcount, early_shares->redo, why);
@ -2982,7 +2982,7 @@ bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername
LOGDEBUG("%s(): %s/%s/%s/%s/%ld,%ld",
__func__,
workinfoid, st = safe_text(workername), nonce,
workinfoid, st = safe_text_nonull(workername), nonce,
errn, cd->tv_sec, cd->tv_usec);
FREENULL(st);
@ -3002,7 +3002,7 @@ bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername
or the authentication information got to ckdb after
the shares ... which shouldn't ever happen */
LOGERR("%s() %s/%ld,%ld %s no user! Share discarded!",
__func__, st = safe_text(username),
__func__, st = safe_text_nonull(username),
cd->tv_sec, cd->tv_usec, cd_buf);
FREENULL(st);
goto tisbad;
@ -3029,7 +3029,7 @@ bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername
btv_to_buf(cd, cd_buf, sizeof(cd_buf));
LOGERR("%s() %s/%ld,%ld %s missing secondaryuserid! "
"Share corrected",
__func__, st = safe_text(username),
__func__, st = safe_text_nonull(username),
cd->tv_sec, cd->tv_usec, cd_buf);
FREENULL(st);
}
@ -3044,7 +3044,7 @@ bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername
LOGERR("%s() %"PRId64"/%s/%ld,%ld %s no workinfo! "
"Early share queued!",
__func__, shares->workinfoid,
st = safe_text(workername),
st = safe_text_nonull(workername),
cd->tv_sec, cd->tv_usec, cd_buf);
FREENULL(st);
shares->redo = 0;
@ -3102,7 +3102,7 @@ static bool shareerrors_process(PGconn *conn, SHAREERRORS *shareerrors,
if (!w_item) {
LOGDEBUG("%s(): new_default_worker failed %"PRId64"/%s/%ld,%ld",
__func__, shareerrors->userid,
st = safe_text(shareerrors->workername),
st = safe_text_nonull(shareerrors->workername),
shareerrors->createdate.tv_sec,
shareerrors->createdate.tv_usec);
FREENULL(st);
@ -3118,7 +3118,7 @@ static bool shareerrors_process(PGconn *conn, SHAREERRORS *shareerrors,
" %"PRId64"/%s/%ld,%ld",
__func__, shareerrors->workinfoid,
shareerrors->userid,
st = safe_text(shareerrors->workername),
st = safe_text_nonull(shareerrors->workername),
shareerrors->createdate.tv_sec,
shareerrors->createdate.tv_usec);
FREENULL(st);
@ -3136,7 +3136,7 @@ static bool shareerrors_process(PGconn *conn, SHAREERRORS *shareerrors,
__func__, sharesummary->complete,
shareerrors->workinfoid,
shareerrors->userid,
st = safe_text(shareerrors->workername),
st = safe_text_nonull(shareerrors->workername),
shareerrors->createdate.tv_sec,
shareerrors->createdate.tv_usec);
FREENULL(st);
@ -3249,7 +3249,7 @@ keep:
LOGERR("%s() %"PRId64"/%s/%ld,%ld %s/%"PRId32"/%"PRId32
" Early share procured",
__func__, early_shareerrors->workinfoid,
st = safe_text(early_shareerrors->workername),
st = safe_text_nonull(early_shareerrors->workername),
early_shareerrors->createdate.tv_sec,
early_shareerrors->createdate.tv_usec, cd_buf,
early_shareerrors->oldcount, early_shareerrors->redo);
@ -3264,7 +3264,7 @@ discard:
LOGERR("%s() %"PRId64"/%s/%ld,%ld %s/%"PRId32"/%"PRId32
" Early share discarded!%s",
__func__, early_shareerrors->workinfoid,
st = safe_text(early_shareerrors->workername),
st = safe_text_nonull(early_shareerrors->workername),
early_shareerrors->createdate.tv_sec,
early_shareerrors->createdate.tv_usec, cd_buf,
early_shareerrors->oldcount, early_shareerrors->redo, why);
@ -3290,7 +3290,7 @@ bool shareerrors_add(PGconn *conn, char *workinfoid, char *username,
LOGDEBUG("%s(): %s/%s/%s/%s/%ld,%ld",
__func__,
workinfoid, st = safe_text(workername), errn,
workinfoid, st = safe_text_nonull(workername), errn,
error, cd->tv_sec, cd->tv_usec);
FREENULL(st);
@ -3307,7 +3307,7 @@ bool shareerrors_add(PGconn *conn, char *workinfoid, char *username,
if (!u_item) {
btv_to_buf(cd, cd_buf, sizeof(cd_buf));
LOGERR("%s() %s/%ld,%ld %s no user! Shareerror discarded!",
__func__, st = safe_text(username),
__func__, st = safe_text_nonull(username),
cd->tv_sec, cd->tv_usec, cd_buf);
FREENULL(st);
goto tisbad;
@ -3330,7 +3330,7 @@ bool shareerrors_add(PGconn *conn, char *workinfoid, char *username,
btv_to_buf(cd, cd_buf, sizeof(cd_buf));
LOGERR("%s() %s/%ld,%ld %s missing secondaryuserid! "
"Sharerror corrected",
__func__, st = safe_text(username),
__func__, st = safe_text_nonull(username),
cd->tv_sec, cd->tv_usec, cd_buf);
FREENULL(st);
}
@ -3345,7 +3345,7 @@ bool shareerrors_add(PGconn *conn, char *workinfoid, char *username,
LOGERR("%s() %"PRId64"/%s/%ld,%ld %s no workinfo! "
"Early shareerror queued!",
__func__, shareerrors->workinfoid,
st = safe_text(workername),
st = safe_text_nonull(workername),
cd->tv_sec, cd->tv_usec, cd_buf);
FREENULL(st);
shareerrors->redo = 0;
@ -3921,7 +3921,7 @@ bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITE
if (wm_item) {
DATA_WORKMARKERS(wm, wm_item);
LOGERR("%s(): attempt to update sharesummary "
"with %s %"PRId64"/%"PRId64"/%s createdate %s"
"with %s %"PRId64"/%"PRId64"/%s "CDDB" %s"
" but processed workmarkers %"PRId64" exists",
__func__, s_row ? "shares" : "shareerrors",
workinfoid, userid, st = safe_text(workername),
@ -3969,7 +3969,7 @@ bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITE
level = LOG_WARNING;
} else
ooof0++;
LOGMSG(level, "%s(): OoO %s createdate (%s) is < summary"
LOGMSG(level, "%s(): OoO %s "CDDB" (%s) is < summary"
" firstshare (%s) (%s)",
__func__, s_row ? "shares" : "shareerrors",
(tmp1 = ctv_to_buf(createdate, NULL, 0)),
@ -3990,7 +3990,7 @@ bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITE
level = LOG_WARNING;
} else
oool0++;
LOGMSG(level, "%s(): OoO %s createdate (%s) is < summary"
LOGMSG(level, "%s(): OoO %s "CDDB" (%s) is < summary"
" lastshare (%s) (%s)",
__func__, s_row ? "shares" : "shareerrors",
(tmp1 = ctv_to_buf(createdate, NULL, 0)),
@ -4004,7 +4004,7 @@ bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITE
LOGDEBUG("%s(): updating sharesummary not '%c'"
" %"PRId64"/%s/%"PRId64"/%s",
__func__, SUMMARY_NEW, row->userid,
st = safe_text(row->workername),
st = safe_text_nonull(row->workername),
row->workinfoid, row->complete);
FREENULL(st);
}
@ -4126,7 +4126,7 @@ bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITE
"shareacc=$9,sharesta=$10,sharedup=$11,sharehi=$12,"
"sharerej=$13,firstshare=$14,lastshare=$15,"
"sharecount=$16,errorcount=$17,lastdiffacc=$18,complete=$19"
",modifydate=$20,modifyby=$21,modifycode=$22,modifyinet=$23 "
","MDDB"=$20,"MBYDB"=$21,"MCODEDB"=$22,"MINETDB"=$23 "
"where userid=$1 and workername=$2 and workinfoid=$3";
res = PQexecParams(conn, upd, par, NULL, (const char **)params, NULL, NULL, 0, CKPQ_WRITE);
@ -4154,7 +4154,7 @@ bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITE
PARCHKVAL(par, 8, params);
upd = "update sharesummary "
"set complete=$4,modifydate=$5,modifyby=$6,modifycode=$7,modifyinet=$8 "
"set complete=$4,"MDDB"=$5,"MBYDB"=$6,"MCODEDB"=$7,"MINETDB"=$8 "
"where userid=$1 and workername=$2 and workinfoid=$3";
res = PQexecParams(conn, upd, par, NULL, (const char **)params, NULL, NULL, 0, CKPQ_WRITE);
@ -4509,7 +4509,7 @@ bool blocks_stats(PGconn *conn, int32_t height, char *blockhash,
row->statsconfirmed[1] = '\0';
HISTORYDATEINIT(row, cd, by, code, inet);
upd = "update blocks set expirydate=$1 where blockhash=$2 and expirydate=$3";
upd = "update blocks set "EDDB"=$1 where blockhash=$2 and "EDDB"=$3";
par = 0;
params[par++] = tv_to_buf(cd, NULL, 0);
params[par++] = str_to_buf(row->blockhash, NULL, 0);
@ -4564,7 +4564,7 @@ bool blocks_stats(PGconn *conn, int32_t height, char *blockhash,
"clientid,enonce1,nonce2,nonce,reward,confirmed,"
"$3,$4,$5,$6,$7,$8,"
"$9,$10,$11,$12,$13 from blocks where "
"blockhash=$1 and expirydate=$2";
"blockhash=$1 and "EDDB"=$2";
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0, CKPQ_WRITE);
rescode = PQresultStatus(res);
@ -4782,7 +4782,7 @@ bool blocks_add(PGconn *conn, char *height, char *blockhash,
goto flail;
}
upd = "update blocks set expirydate=$1 where blockhash=$2 and expirydate=$3";
upd = "update blocks set "EDDB"=$1 where blockhash=$2 and "EDDB"=$3";
par = 0;
params[par++] = tv_to_buf(cd, NULL, 0);
params[par++] = str_to_buf(row->blockhash, NULL, 0);
@ -4849,7 +4849,7 @@ bool blocks_add(PGconn *conn, char *height, char *blockhash,
"clientid,enonce1,nonce2,nonce,reward,"
"$3,$4,$5,$6,$7,elapsed,statsconfirmed,"
"$8,$9,$10,$11,$12 from blocks where "
"blockhash=$1 and expirydate=$2";
"blockhash=$1 and "EDDB"=$2";
} else {
HISTORYDATEPARAMS(params, par, row);
PARCHKVAL(par, 3 + HISTORYDATECOUNT, params); // 8 as per ins
@ -4865,7 +4865,7 @@ bool blocks_add(PGconn *conn, char *height, char *blockhash,
"$3,diffacc,diffinv,shareacc,shareinv,elapsed,"
"statsconfirmed,"
"$4,$5,$6,$7,$8 from blocks where "
"blockhash=$1 and expirydate=$2";
"blockhash=$1 and "EDDB"=$2";
}
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0, CKPQ_WRITE);
@ -4956,7 +4956,7 @@ flail:
snprintf(tmp, sizeof(tmp),
" Reward: %f, Worker: %s, ShareEst: %.1f %s%s%% UTC:%s",
BTC_TO_D(row->reward),
st = safe_text(row->workername),
st = safe_text_nonull(row->workername),
pool.diffacc, est, pct, cd_buf);
FREENULL(st);
if (pool.workinfoid < row->workinfoid) {
@ -5208,8 +5208,8 @@ bool miningpayouts_add(PGconn *conn, bool add, K_ITEM *mp_item,
DATA_MININGPAYOUTS(oldmp, *old_mp_item);
upd = "update miningpayouts set expirydate=$1 where payoutid=$2"
" and userid=$3 and expirydate=$4";
upd = "update miningpayouts set "EDDB"=$1 where payoutid=$2"
" and userid=$3 and "EDDB"=$4";
par = 0;
params[par++] = tv_to_buf(cd, NULL, 0);
params[par++] = bigint_to_buf(oldmp->payoutid, NULL, 0);
@ -5428,8 +5428,8 @@ bool payouts_add(PGconn *conn, bool add, K_ITEM *p_item, K_ITEM **old_p_item,
DATA_PAYOUTS(oldpayouts, *old_p_item);
upd = "update payouts set expirydate=$1 where payoutid=$2"
" and expirydate=$3";
upd = "update payouts set "EDDB"=$1 where payoutid=$2"
" and "EDDB"=$3";
par = 0;
params[par++] = tv_to_buf(cd, NULL, 0);
params[par++] = bigint_to_buf(oldpayouts->payoutid, NULL, 0);
@ -5686,7 +5686,7 @@ bool auths_add(PGconn *conn, char *poolinstance, char *username,
} else {
LOGDEBUG("%s(): unknown user '%s'",
__func__,
st = safe_text(username));
st = safe_text_nonull(username));
FREENULL(st);
}
if (!u_item)
@ -5727,7 +5727,7 @@ bool auths_add(PGconn *conn, char *poolinstance, char *username,
// Shouldn't actually be possible unless twice in the logs
tv_to_buf(cd, cd_buf, sizeof(cd_buf));
LOGERR("%s(): Duplicate auths ignored %s/%s/%s",
__func__, poolinstance, st = safe_text(workername),
__func__, poolinstance, st = safe_text_nonull(workername),
cd_buf);
FREENULL(st);
@ -5922,7 +5922,7 @@ bool poolstats_fill(PGconn *conn)
"poolinstance,elapsed,users,workers,hashrate,"
"hashrate5m,hashrate1hr,hashrate24hr"
SIMPLEDATECONTROL
" from poolstats where createdate>");
" from poolstats where "CDDB">");
APPEND_REALLOC(sel, off, len, stamp);
res = PQexec(conn, sel, CKPQ_READ);
@ -6056,7 +6056,7 @@ bool userstats_add(char *poolinstance, char *elapsed, char *username,
if (!u_item) {
LOGERR("%s(): unknown user '%s'",
__func__,
st = safe_text(username));
st = safe_text_nonull(username));
FREENULL(st);
return false;
}
@ -6166,8 +6166,8 @@ bool workerstats_add(char *poolinstance, char *elapsed, char *username,
char *usr = NULL, *wrk = NULL;
LOGERR("%s(): unknown user '%s' (worker=%s)",
__func__,
usr = safe_text(username),
wrk = safe_text(workername));
usr = safe_text_nonull(username),
wrk = safe_text_nonull(workername));
FREENULL(usr);
FREENULL(wrk);
return false;
@ -6261,7 +6261,7 @@ bool markersummary_add(PGconn *conn, K_ITEM *ms_item, char *by, char *code,
LOGDEBUG("%s() adding ms %"PRId64"/%"PRId64"/%s/%.0f",
__func__, row->markerid, row->userid,
st = safe_text(row->workername),
st = safe_text_nonull(row->workername),
row->diffacc);
FREENULL(st);
@ -6545,8 +6545,8 @@ bool _workmarkers_process(PGconn *conn, bool already, bool add,
begun = true;
}
upd = "update workmarkers set expirydate=$1 where markerid=$2"
" and expirydate=$3";
upd = "update workmarkers set "EDDB"=$1 where markerid=$2"
" and "EDDB"=$3";
par = 0;
params[par++] = tv_to_buf(cd, NULL, 0);
params[par++] = bigint_to_buf(oldworkmarkers->markerid, NULL, 0);
@ -6873,8 +6873,8 @@ bool _marks_process(PGconn *conn, bool add, char *poolinstance,
begun = true;
upd = "update marks set expirydate=$1 where workinfoid=$2"
" and expirydate=$3";
upd = "update marks set "EDDB"=$1 where workinfoid=$2"
" and "EDDB"=$3";
par = 0;
params[par++] = tv_to_buf(cd, NULL, 0);
params[par++] = bigint_to_buf(workinfoid, NULL, 0);

4
src/ckpool.c

@ -176,7 +176,7 @@ ckmsgq_t *create_ckmsgqs(ckpool_t *ckp, const char *name, const void *func, cons
}
/* Generic function for adding messages to a ckmsgq linked list and signal the
* ckmsgq parsing thread to wake up and process it. */
* ckmsgq parsing thread(s) to wake up and process it. */
void ckmsgq_add(ckmsgq_t *ckmsgq, void *data)
{
ckmsg_t *msg = ckalloc(sizeof(ckmsg_t));
@ -186,7 +186,7 @@ void ckmsgq_add(ckmsgq_t *ckmsgq, void *data)
mutex_lock(ckmsgq->lock);
ckmsgq->messages++;
DL_APPEND(ckmsgq->msgs, msg);
pthread_cond_signal(ckmsgq->cond);
pthread_cond_broadcast(ckmsgq->cond);
mutex_unlock(ckmsgq->lock);
}

10
src/klist.c

@ -205,6 +205,11 @@ void _k_add_head(K_LIST *list, K_ITEM *item, KLIST_FFL_ARGS)
list->name, __func__, item->name, KLIST_FFL_PASS);
}
if (item->prev || item->next) {
quithere(1, "%s() added item %s still linked" KLIST_FFL,
__func__, item->name, KLIST_FFL_PASS);
}
item->prev = NULL;
item->next = list->head;
if (list->head)
@ -241,6 +246,11 @@ void _k_add_tail(K_LIST *list, K_ITEM *item, KLIST_FFL_ARGS)
list->name, __func__, KLIST_FFL_PASS);
}
if (item->prev || item->next) {
quithere(1, "%s() added item %s still linked" KLIST_FFL,
__func__, item->name, KLIST_FFL_PASS);
}
item->prev = list->tail;
item->next = NULL;
if (list->tail)

3
src/libckpool.h

@ -194,6 +194,9 @@ void logmsg(int loglevel, const char *fmt, ...);
#define DEFLOGBUFSIZ 512
#define LOGMSGBUF(__lvl, __buf) do { \
logmsg(__lvl, "%s", __buf); \
} while(0)
#define LOGMSGSIZ(__siz, __lvl, __fmt, ...) do { \
char tmp42[__siz]; \
snprintf(tmp42, sizeof(tmp42), __fmt, ##__VA_ARGS__); \

Loading…
Cancel
Save