|
|
@ -1742,6 +1742,7 @@ static int64_t nextid(PGconn *conn, char *idname, int64_t increment, |
|
|
|
tv_t *cd, char *by, char *code, char *inet) |
|
|
|
tv_t *cd, char *by, char *code, char *inet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ExecStatusType rescode; |
|
|
|
ExecStatusType rescode; |
|
|
|
|
|
|
|
bool conned = false; |
|
|
|
PGresult *res; |
|
|
|
PGresult *res; |
|
|
|
char qry[1024]; |
|
|
|
char qry[1024]; |
|
|
|
char *params[5]; |
|
|
|
char *params[5]; |
|
|
@ -1757,6 +1758,11 @@ static int64_t nextid(PGconn *conn, char *idname, int64_t increment, |
|
|
|
"where idname='%s' for update", |
|
|
|
"where idname='%s' for update", |
|
|
|
idname); |
|
|
|
idname); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (conn == NULL) { |
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
conned = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res = PQexec(conn, qry); |
|
|
|
res = PQexec(conn, qry); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
if (!PGOK(rescode)) { |
|
|
|
if (!PGOK(rescode)) { |
|
|
@ -1811,6 +1817,8 @@ static int64_t nextid(PGconn *conn, char *idname, int64_t increment, |
|
|
|
free(params[n]); |
|
|
|
free(params[n]); |
|
|
|
cleanup: |
|
|
|
cleanup: |
|
|
|
PQclear(res); |
|
|
|
PQclear(res); |
|
|
|
|
|
|
|
if (conned) |
|
|
|
|
|
|
|
PQfinish(conn); |
|
|
|
return lastid; |
|
|
|
return lastid; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2016,6 +2024,7 @@ static bool users_add(PGconn *conn, char *username, char *emailaddress, char *pa |
|
|
|
tv_t *now, char *by, char *code, char *inet) |
|
|
|
tv_t *now, char *by, char *code, char *inet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ExecStatusType rescode; |
|
|
|
ExecStatusType rescode; |
|
|
|
|
|
|
|
bool conned = false; |
|
|
|
PGresult *res; |
|
|
|
PGresult *res; |
|
|
|
K_ITEM *item; |
|
|
|
K_ITEM *item; |
|
|
|
int n; |
|
|
|
int n; |
|
|
@ -2072,6 +2081,11 @@ static bool users_add(PGconn *conn, char *username, char *emailaddress, char *pa |
|
|
|
"secondaryuserid" |
|
|
|
"secondaryuserid" |
|
|
|
HISTORYDATECONTROL ") values (" PQPARAM11 ")"; |
|
|
|
HISTORYDATECONTROL ") values (" PQPARAM11 ")"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!conn) { |
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
conned = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0); |
|
|
|
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
if (!PGOK(rescode)) { |
|
|
|
if (!PGOK(rescode)) { |
|
|
@ -2082,6 +2096,8 @@ static bool users_add(PGconn *conn, char *username, char *emailaddress, char *pa |
|
|
|
ok = true; |
|
|
|
ok = true; |
|
|
|
unparam: |
|
|
|
unparam: |
|
|
|
PQclear(res); |
|
|
|
PQclear(res); |
|
|
|
|
|
|
|
if (conned) |
|
|
|
|
|
|
|
PQfinish(conn); |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
free(params[n]); |
|
|
|
free(params[n]); |
|
|
|
unitem: |
|
|
|
unitem: |
|
|
@ -2245,6 +2261,7 @@ static K_ITEM *workers_add(PGconn *conn, int64_t userid, char *workername, |
|
|
|
char *code, char *inet, tv_t *cd) |
|
|
|
char *code, char *inet, tv_t *cd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ExecStatusType rescode; |
|
|
|
ExecStatusType rescode; |
|
|
|
|
|
|
|
bool conned = false; |
|
|
|
PGresult *res; |
|
|
|
PGresult *res; |
|
|
|
K_ITEM *item, *ret = NULL; |
|
|
|
K_ITEM *item, *ret = NULL; |
|
|
|
int n; |
|
|
|
int n; |
|
|
@ -2263,6 +2280,11 @@ static K_ITEM *workers_add(PGconn *conn, int64_t userid, char *workername, |
|
|
|
|
|
|
|
|
|
|
|
row = DATA_WORKERS(item); |
|
|
|
row = DATA_WORKERS(item); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (conn == NULL) { |
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
conned = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
row->workerid = nextid(conn, "workerid", (int64_t)1, cd, by, code, inet); |
|
|
|
row->workerid = nextid(conn, "workerid", (int64_t)1, cd, by, code, inet); |
|
|
|
if (row->workerid == 0) |
|
|
|
if (row->workerid == 0) |
|
|
|
goto unitem; |
|
|
|
goto unitem; |
|
|
@ -2329,6 +2351,8 @@ unparam: |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
free(params[n]); |
|
|
|
free(params[n]); |
|
|
|
unitem: |
|
|
|
unitem: |
|
|
|
|
|
|
|
if (conned) |
|
|
|
|
|
|
|
PQfinish(conn); |
|
|
|
K_WLOCK(workers_free); |
|
|
|
K_WLOCK(workers_free); |
|
|
|
if (!ret) |
|
|
|
if (!ret) |
|
|
|
k_add_head(workers_free, item); |
|
|
|
k_add_head(workers_free, item); |
|
|
@ -2346,6 +2370,7 @@ static bool workers_update(PGconn *conn, K_ITEM *item, char *difficultydefault, |
|
|
|
char *by, char *code, char *inet, tv_t *cd) |
|
|
|
char *by, char *code, char *inet, tv_t *cd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ExecStatusType rescode; |
|
|
|
ExecStatusType rescode; |
|
|
|
|
|
|
|
bool conned = false; |
|
|
|
PGresult *res; |
|
|
|
PGresult *res; |
|
|
|
int n; |
|
|
|
int n; |
|
|
|
WORKERS *row; |
|
|
|
WORKERS *row; |
|
|
@ -2402,6 +2427,11 @@ static bool workers_update(PGconn *conn, K_ITEM *item, char *difficultydefault, |
|
|
|
params[par++] = tv_to_buf((tv_t *)&default_expiry, NULL, 0); |
|
|
|
params[par++] = tv_to_buf((tv_t *)&default_expiry, NULL, 0); |
|
|
|
PARCHKVAL(par, 3, params); |
|
|
|
PARCHKVAL(par, 3, params); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (conn == NULL) { |
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
conned = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res = PQexec(conn, "Begin"); |
|
|
|
res = PQexec(conn, "Begin"); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
if (!PGOK(rescode)) { |
|
|
|
if (!PGOK(rescode)) { |
|
|
@ -2457,6 +2487,8 @@ static bool workers_update(PGconn *conn, K_ITEM *item, char *difficultydefault, |
|
|
|
ok = true; |
|
|
|
ok = true; |
|
|
|
unparam: |
|
|
|
unparam: |
|
|
|
PQclear(res); |
|
|
|
PQclear(res); |
|
|
|
|
|
|
|
if (conned) |
|
|
|
|
|
|
|
PQfinish(conn); |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
free(params[n]); |
|
|
|
free(params[n]); |
|
|
|
early: |
|
|
|
early: |
|
|
@ -2853,6 +2885,7 @@ static int64_t workinfo_add(PGconn *conn, char *workinfoidstr, char *poolinstanc |
|
|
|
char *code, char *inet, tv_t *cd, bool igndup) |
|
|
|
char *code, char *inet, tv_t *cd, bool igndup) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ExecStatusType rescode; |
|
|
|
ExecStatusType rescode; |
|
|
|
|
|
|
|
bool conned = false; |
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
PGresult *res; |
|
|
|
PGresult *res; |
|
|
|
K_ITEM *item; |
|
|
|
K_ITEM *item; |
|
|
@ -2914,6 +2947,11 @@ static int64_t workinfo_add(PGconn *conn, char *workinfoidstr, char *poolinstanc |
|
|
|
"prevhash,coinbase1,coinbase2,version,bits,ntime,reward" |
|
|
|
"prevhash,coinbase1,coinbase2,version,bits,ntime,reward" |
|
|
|
HISTORYDATECONTROL ") values (" PQPARAM16 ")"; |
|
|
|
HISTORYDATECONTROL ") values (" PQPARAM16 ")"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!conn) { |
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
conned = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0); |
|
|
|
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
if (!PGOK(rescode)) { |
|
|
|
if (!PGOK(rescode)) { |
|
|
@ -2925,6 +2963,8 @@ static int64_t workinfo_add(PGconn *conn, char *workinfoidstr, char *poolinstanc |
|
|
|
|
|
|
|
|
|
|
|
unparam: |
|
|
|
unparam: |
|
|
|
PQclear(res); |
|
|
|
PQclear(res); |
|
|
|
|
|
|
|
if (conned) |
|
|
|
|
|
|
|
PQfinish(conn); |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
free(params[n]); |
|
|
|
free(params[n]); |
|
|
|
|
|
|
|
|
|
|
@ -3271,9 +3311,10 @@ static void zero_sharesummary(SHARESUMMARY *row, tv_t *cd) |
|
|
|
static K_ITEM *find_sharesummary(int64_t userid, char *workername, int64_t workinfoid); |
|
|
|
static K_ITEM *find_sharesummary(int64_t userid, char *workername, int64_t workinfoid); |
|
|
|
|
|
|
|
|
|
|
|
// Memory (and log file) only
|
|
|
|
// Memory (and log file) only
|
|
|
|
static bool shares_add(char *workinfoid, char *username, char *workername, char *clientid, |
|
|
|
static bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername, |
|
|
|
char *enonce1, char *nonce2, char *nonce, char *diff, char *sdiff, |
|
|
|
char *clientid, char *enonce1, char *nonce2, char *nonce, |
|
|
|
char *secondaryuserid, char *by, char *code, char *inet, tv_t *cd) |
|
|
|
char *diff, char *sdiff, char *secondaryuserid, char *by, |
|
|
|
|
|
|
|
char *code, char *inet, tv_t *cd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
K_ITEM *s_item, *u_item, *wi_item, *w_item, *ss_item; |
|
|
|
K_ITEM *s_item, *u_item, *wi_item, *w_item, *ss_item; |
|
|
|
SHARES *shares; |
|
|
|
SHARES *shares; |
|
|
@ -3311,7 +3352,7 @@ static bool shares_add(char *workinfoid, char *username, char *workername, char |
|
|
|
if (!wi_item) |
|
|
|
if (!wi_item) |
|
|
|
goto unitem; |
|
|
|
goto unitem; |
|
|
|
|
|
|
|
|
|
|
|
w_item = new_default_worker(NULL, false, shares->userid, shares->workername, |
|
|
|
w_item = new_default_worker(conn, false, shares->userid, shares->workername, |
|
|
|
by, code, inet, cd); |
|
|
|
by, code, inet, cd); |
|
|
|
if (!w_item) |
|
|
|
if (!w_item) |
|
|
|
goto unitem; |
|
|
|
goto unitem; |
|
|
@ -3335,7 +3376,7 @@ static bool shares_add(char *workinfoid, char *username, char *workername, char |
|
|
|
|
|
|
|
|
|
|
|
workerstatus_update(NULL, shares, NULL, NULL); |
|
|
|
workerstatus_update(NULL, shares, NULL, NULL); |
|
|
|
|
|
|
|
|
|
|
|
sharesummary_update(NULL, shares, NULL, NULL, by, code, inet, cd); |
|
|
|
sharesummary_update(conn, shares, NULL, NULL, by, code, inet, cd); |
|
|
|
|
|
|
|
|
|
|
|
ok = true; |
|
|
|
ok = true; |
|
|
|
unitem: |
|
|
|
unitem: |
|
|
@ -3381,9 +3422,10 @@ static cmp_t cmp_shareerrors(K_ITEM *a, K_ITEM *b) |
|
|
|
|
|
|
|
|
|
|
|
// Memory (and log file) only
|
|
|
|
// Memory (and log file) only
|
|
|
|
// TODO: handle shareerrors that appear after a workinfoid is aged or doesn't exist?
|
|
|
|
// TODO: handle shareerrors that appear after a workinfoid is aged or doesn't exist?
|
|
|
|
static bool shareerrors_add(char *workinfoid, char *username, char *workername, |
|
|
|
static bool shareerrors_add(PGconn *conn, char *workinfoid, char *username, |
|
|
|
char *clientid, char *errn, char *error, char *secondaryuserid, |
|
|
|
char *workername, char *clientid, char *errn, |
|
|
|
char *by, char *code, char *inet, tv_t *cd) |
|
|
|
char *error, char *secondaryuserid, char *by, |
|
|
|
|
|
|
|
char *code, char *inet, tv_t *cd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
K_ITEM *s_item, *u_item, *wi_item, *w_item, *ss_item; |
|
|
|
K_ITEM *s_item, *u_item, *wi_item, *w_item, *ss_item; |
|
|
|
SHAREERRORS *shareerrors; |
|
|
|
SHAREERRORS *shareerrors; |
|
|
@ -3440,7 +3482,7 @@ static bool shareerrors_add(char *workinfoid, char *username, char *workername, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sharesummary_update(NULL, NULL, shareerrors, NULL, by, code, inet, cd); |
|
|
|
sharesummary_update(conn, NULL, shareerrors, NULL, by, code, inet, cd); |
|
|
|
|
|
|
|
|
|
|
|
ok = true; |
|
|
|
ok = true; |
|
|
|
unitem: |
|
|
|
unitem: |
|
|
@ -4042,6 +4084,7 @@ static bool blocks_add(PGconn *conn, char *height, char *blockhash, |
|
|
|
bool igndup, char *id) |
|
|
|
bool igndup, char *id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ExecStatusType rescode; |
|
|
|
ExecStatusType rescode; |
|
|
|
|
|
|
|
bool conned = false; |
|
|
|
PGresult *res = NULL; |
|
|
|
PGresult *res = NULL; |
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
K_ITEM *item, *u_item; |
|
|
|
K_ITEM *item, *u_item; |
|
|
@ -4111,6 +4154,11 @@ static bool blocks_add(PGconn *conn, char *height, char *blockhash, |
|
|
|
"clientid,enonce1,nonce2,nonce,reward,confirmed" |
|
|
|
"clientid,enonce1,nonce2,nonce,reward,confirmed" |
|
|
|
HISTORYDATECONTROL ") values (" PQPARAM16 ")"; |
|
|
|
HISTORYDATECONTROL ") values (" PQPARAM16 ")"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (conn == NULL) { |
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
conned = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0); |
|
|
|
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
if (!PGOK(rescode)) { |
|
|
|
if (!PGOK(rescode)) { |
|
|
@ -4127,6 +4175,11 @@ static bool blocks_add(PGconn *conn, char *height, char *blockhash, |
|
|
|
params[par++] = tv_to_buf((tv_t *)&default_expiry, NULL, 0); |
|
|
|
params[par++] = tv_to_buf((tv_t *)&default_expiry, NULL, 0); |
|
|
|
PARCHKVAL(par, 3, params); |
|
|
|
PARCHKVAL(par, 3, params); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (conn == NULL) { |
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
conned = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res = PQexec(conn, "Begin"); |
|
|
|
res = PQexec(conn, "Begin"); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
if (!PGOK(rescode)) { |
|
|
|
if (!PGOK(rescode)) { |
|
|
@ -4186,6 +4239,9 @@ unparam: |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
free(params[n]); |
|
|
|
free(params[n]); |
|
|
|
flail: |
|
|
|
flail: |
|
|
|
|
|
|
|
if (conned) |
|
|
|
|
|
|
|
PQfinish(conn); |
|
|
|
|
|
|
|
|
|
|
|
K_WLOCK(blocks_free); |
|
|
|
K_WLOCK(blocks_free); |
|
|
|
if (!ok) |
|
|
|
if (!ok) |
|
|
|
k_add_head(blocks_free, item); |
|
|
|
k_add_head(blocks_free, item); |
|
|
@ -4365,6 +4421,7 @@ static char *auths_add(PGconn *conn, char *poolinstance, char *username, |
|
|
|
tv_t *cd, bool igndup) |
|
|
|
tv_t *cd, bool igndup) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ExecStatusType rescode; |
|
|
|
ExecStatusType rescode; |
|
|
|
|
|
|
|
bool conned = false; |
|
|
|
PGresult *res; |
|
|
|
PGresult *res; |
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
K_ITEM *a_item, *u_item; |
|
|
|
K_ITEM *a_item, *u_item; |
|
|
@ -4411,6 +4468,11 @@ static char *auths_add(PGconn *conn, char *poolinstance, char *username, |
|
|
|
// Update even if DB fails
|
|
|
|
// Update even if DB fails
|
|
|
|
workerstatus_update(row, NULL, NULL, NULL); |
|
|
|
workerstatus_update(row, NULL, NULL, NULL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (conn == NULL) { |
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
conned = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
row->authid = nextid(conn, "authid", (int64_t)1, cd, by, code, inet); |
|
|
|
row->authid = nextid(conn, "authid", (int64_t)1, cd, by, code, inet); |
|
|
|
if (row->authid == 0) |
|
|
|
if (row->authid == 0) |
|
|
|
goto unitem; |
|
|
|
goto unitem; |
|
|
@ -4444,6 +4506,8 @@ unparam: |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
free(params[n]); |
|
|
|
free(params[n]); |
|
|
|
unitem: |
|
|
|
unitem: |
|
|
|
|
|
|
|
if (conned) |
|
|
|
|
|
|
|
PQfinish(conn); |
|
|
|
K_WLOCK(auths_free); |
|
|
|
K_WLOCK(auths_free); |
|
|
|
if (!secuserid) |
|
|
|
if (!secuserid) |
|
|
|
k_add_head(auths_free, a_item); |
|
|
|
k_add_head(auths_free, a_item); |
|
|
@ -4595,6 +4659,7 @@ static bool poolstats_add(PGconn *conn, bool store, char *poolinstance, |
|
|
|
bool igndup) |
|
|
|
bool igndup) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ExecStatusType rescode; |
|
|
|
ExecStatusType rescode; |
|
|
|
|
|
|
|
bool conned = false; |
|
|
|
PGresult *res; |
|
|
|
PGresult *res; |
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
K_ITEM *p_item; |
|
|
|
K_ITEM *p_item; |
|
|
@ -4652,6 +4717,11 @@ static bool poolstats_add(PGconn *conn, bool store, char *poolinstance, |
|
|
|
"hashrate5m,hashrate1hr,hashrate24hr" |
|
|
|
"hashrate5m,hashrate1hr,hashrate24hr" |
|
|
|
SIMPLEDATECONTROL ") values (" PQPARAM12 ")"; |
|
|
|
SIMPLEDATECONTROL ") values (" PQPARAM12 ")"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!conn) { |
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
conned = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0); |
|
|
|
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
if (!PGOK(rescode)) { |
|
|
|
if (!PGOK(rescode)) { |
|
|
@ -4666,6 +4736,8 @@ static bool poolstats_add(PGconn *conn, bool store, char *poolinstance, |
|
|
|
unparam: |
|
|
|
unparam: |
|
|
|
if (store) { |
|
|
|
if (store) { |
|
|
|
PQclear(res); |
|
|
|
PQclear(res); |
|
|
|
|
|
|
|
if (conned) |
|
|
|
|
|
|
|
PQfinish(conn); |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
free(params[n]); |
|
|
|
free(params[n]); |
|
|
|
} |
|
|
|
} |
|
|
@ -4909,6 +4981,7 @@ static cmp_t cmp_userstats_workerstatus(K_ITEM *a, K_ITEM *b) |
|
|
|
static bool userstats_add_db(PGconn *conn, USERSTATS *row) |
|
|
|
static bool userstats_add_db(PGconn *conn, USERSTATS *row) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ExecStatusType rescode; |
|
|
|
ExecStatusType rescode; |
|
|
|
|
|
|
|
bool conned = false; |
|
|
|
PGresult *res; |
|
|
|
PGresult *res; |
|
|
|
char *ins; |
|
|
|
char *ins; |
|
|
|
bool ok = false; |
|
|
|
bool ok = false; |
|
|
@ -4937,6 +5010,11 @@ static bool userstats_add_db(PGconn *conn, USERSTATS *row) |
|
|
|
"hashrate24hr,summarylevel,summarycount,statsdate" |
|
|
|
"hashrate24hr,summarylevel,summarycount,statsdate" |
|
|
|
SIMPLEDATECONTROL ") values (" PQPARAM14 ")"; |
|
|
|
SIMPLEDATECONTROL ") values (" PQPARAM14 ")"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (conn == NULL) { |
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
conned = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0); |
|
|
|
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
if (!PGOK(rescode)) { |
|
|
|
if (!PGOK(rescode)) { |
|
|
@ -4947,6 +5025,8 @@ static bool userstats_add_db(PGconn *conn, USERSTATS *row) |
|
|
|
ok = true; |
|
|
|
ok = true; |
|
|
|
unparam: |
|
|
|
unparam: |
|
|
|
PQclear(res); |
|
|
|
PQclear(res); |
|
|
|
|
|
|
|
if (conned) |
|
|
|
|
|
|
|
PQfinish(conn); |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
free(params[n]); |
|
|
|
free(params[n]); |
|
|
|
|
|
|
|
|
|
|
@ -5339,7 +5419,7 @@ static bool check_db_version(PGconn *conn) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static bool getdata() |
|
|
|
static bool getdata1() |
|
|
|
{ |
|
|
|
{ |
|
|
|
PGconn *conn = dbconnect(); |
|
|
|
PGconn *conn = dbconnect(); |
|
|
|
bool ok = true; |
|
|
|
bool ok = true; |
|
|
@ -5350,25 +5430,36 @@ static bool getdata() |
|
|
|
goto matane; |
|
|
|
goto matane; |
|
|
|
if (!(ok = workers_fill(conn))) |
|
|
|
if (!(ok = workers_fill(conn))) |
|
|
|
goto matane; |
|
|
|
goto matane; |
|
|
|
|
|
|
|
ok = auths_fill(conn); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
matane: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PQfinish(conn); |
|
|
|
|
|
|
|
return ok; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool getdata2() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
PGconn *conn = dbconnect(); |
|
|
|
|
|
|
|
bool ok = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!(ok = blocks_fill(conn))) |
|
|
|
|
|
|
|
goto sukamudai; |
|
|
|
if (!(ok = payments_fill(conn))) |
|
|
|
if (!(ok = payments_fill(conn))) |
|
|
|
goto matane; |
|
|
|
goto sukamudai; |
|
|
|
if (!(ok = workinfo_fill(conn))) |
|
|
|
if (!(ok = workinfo_fill(conn))) |
|
|
|
goto matane; |
|
|
|
goto sukamudai; |
|
|
|
if (!(ok = shares_fill())) |
|
|
|
if (!(ok = shares_fill())) |
|
|
|
goto matane; |
|
|
|
goto sukamudai; |
|
|
|
if (!(ok = shareerrors_fill())) |
|
|
|
if (!(ok = shareerrors_fill())) |
|
|
|
goto matane; |
|
|
|
goto sukamudai; |
|
|
|
if (!(ok = sharesummary_fill(conn))) |
|
|
|
if (!(ok = sharesummary_fill(conn))) |
|
|
|
goto matane; |
|
|
|
goto sukamudai; |
|
|
|
if (!(ok = blocks_fill(conn))) |
|
|
|
|
|
|
|
goto matane; |
|
|
|
|
|
|
|
if (!(ok = auths_fill(conn))) |
|
|
|
|
|
|
|
goto matane; |
|
|
|
|
|
|
|
if (!(ok = poolstats_fill(conn))) |
|
|
|
if (!(ok = poolstats_fill(conn))) |
|
|
|
goto matane; |
|
|
|
goto sukamudai; |
|
|
|
ok = userstats_fill(conn); |
|
|
|
ok = userstats_fill(conn); |
|
|
|
|
|
|
|
|
|
|
|
matane: |
|
|
|
sukamudai: |
|
|
|
|
|
|
|
|
|
|
|
PQfinish(conn); |
|
|
|
PQfinish(conn); |
|
|
|
return ok; |
|
|
|
return ok; |
|
|
@ -5623,7 +5714,10 @@ static bool setup_data() |
|
|
|
workerstatus_store = k_new_store(workerstatus_free); |
|
|
|
workerstatus_store = k_new_store(workerstatus_free); |
|
|
|
workerstatus_root = new_ktree(); |
|
|
|
workerstatus_root = new_ktree(); |
|
|
|
|
|
|
|
|
|
|
|
if (!getdata()) |
|
|
|
if (!getdata1()) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!getdata2()) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
db_load_complete = true; |
|
|
|
db_load_complete = true; |
|
|
@ -5651,14 +5745,13 @@ static bool setup_data() |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_adduser(char *cmd, char *id, tv_t *now, char *by, char *code, char *inet, |
|
|
|
static char *cmd_adduser(PGconn *conn, char *cmd, char *id, tv_t *now, char *by, |
|
|
|
__maybe_unused tv_t *notcd) |
|
|
|
char *code, char *inet, __maybe_unused tv_t *notcd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char reply[1024] = ""; |
|
|
|
char reply[1024] = ""; |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
|
|
|
|
|
|
|
|
K_ITEM *i_username, *i_emailaddress, *i_passwordhash; |
|
|
|
K_ITEM *i_username, *i_emailaddress, *i_passwordhash; |
|
|
|
PGconn *conn; |
|
|
|
|
|
|
|
bool ok; |
|
|
|
bool ok; |
|
|
|
|
|
|
|
|
|
|
|
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); |
|
|
|
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); |
|
|
@ -5675,12 +5768,10 @@ static char *cmd_adduser(char *cmd, char *id, tv_t *now, char *by, char *code, c |
|
|
|
if (!i_passwordhash) |
|
|
|
if (!i_passwordhash) |
|
|
|
return strdup(reply); |
|
|
|
return strdup(reply); |
|
|
|
|
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
ok = users_add(conn, DATA_TRANSFER(i_username)->data, |
|
|
|
ok = users_add(conn, DATA_TRANSFER(i_username)->data, |
|
|
|
DATA_TRANSFER(i_emailaddress)->data, |
|
|
|
DATA_TRANSFER(i_emailaddress)->data, |
|
|
|
DATA_TRANSFER(i_passwordhash)->data, |
|
|
|
DATA_TRANSFER(i_passwordhash)->data, |
|
|
|
now, by, code, inet); |
|
|
|
now, by, code, inet); |
|
|
|
PQfinish(conn); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ok) { |
|
|
|
if (!ok) { |
|
|
|
LOGERR("%s.failed.DBE", id); |
|
|
|
LOGERR("%s.failed.DBE", id); |
|
|
@ -5691,7 +5782,8 @@ static char *cmd_adduser(char *cmd, char *id, tv_t *now, char *by, char *code, c |
|
|
|
return strdup(reply); |
|
|
|
return strdup(reply); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_chkpass(char *cmd, char *id, __maybe_unused tv_t *now, __maybe_unused char *by, |
|
|
|
static char *cmd_chkpass(__maybe_unused PGconn *conn, char *cmd, char *id, |
|
|
|
|
|
|
|
__maybe_unused 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) |
|
|
|
__maybe_unused tv_t *notcd) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -5729,13 +5821,12 @@ static char *cmd_chkpass(char *cmd, char *id, __maybe_unused tv_t *now, __maybe_ |
|
|
|
return strdup("ok."); |
|
|
|
return strdup("ok."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_poolstats_do(char *cmd, char *id, char *by, char *code, |
|
|
|
static char *cmd_poolstats_do(PGconn *conn, char *cmd, char *id, char *by, |
|
|
|
char *inet, tv_t *cd, bool igndup) |
|
|
|
char *code, char *inet, tv_t *cd, bool igndup) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char reply[1024] = ""; |
|
|
|
char reply[1024] = ""; |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
PGconn *conn; |
|
|
|
|
|
|
|
bool store; |
|
|
|
bool store; |
|
|
|
|
|
|
|
|
|
|
|
// log to logfile
|
|
|
|
// log to logfile
|
|
|
@ -5803,7 +5894,6 @@ static char *cmd_poolstats_do(char *cmd, char *id, char *by, char *code, |
|
|
|
store = false; |
|
|
|
store = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
ok = poolstats_add(conn, store, DATA_TRANSFER(i_poolinstance)->data, |
|
|
|
ok = poolstats_add(conn, store, DATA_TRANSFER(i_poolinstance)->data, |
|
|
|
DATA_TRANSFER(i_elapsed)->data, |
|
|
|
DATA_TRANSFER(i_elapsed)->data, |
|
|
|
DATA_TRANSFER(i_users)->data, |
|
|
|
DATA_TRANSFER(i_users)->data, |
|
|
@ -5813,7 +5903,6 @@ static char *cmd_poolstats_do(char *cmd, char *id, char *by, char *code, |
|
|
|
DATA_TRANSFER(i_hashrate1hr)->data, |
|
|
|
DATA_TRANSFER(i_hashrate1hr)->data, |
|
|
|
DATA_TRANSFER(i_hashrate24hr)->data, |
|
|
|
DATA_TRANSFER(i_hashrate24hr)->data, |
|
|
|
by, code, inet, cd, igndup); |
|
|
|
by, code, inet, cd, igndup); |
|
|
|
PQfinish(conn); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ok) { |
|
|
|
if (!ok) { |
|
|
|
LOGERR("%s.failed.DBE", id); |
|
|
|
LOGERR("%s.failed.DBE", id); |
|
|
@ -5824,8 +5913,9 @@ static char *cmd_poolstats_do(char *cmd, char *id, char *by, char *code, |
|
|
|
return strdup(reply); |
|
|
|
return strdup(reply); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_poolstats(char *cmd, char *id, __maybe_unused tv_t *notnow, |
|
|
|
static char *cmd_poolstats(PGconn *conn, char *cmd, char *id, |
|
|
|
char *by, char *code, char *inet, tv_t *cd) |
|
|
|
__maybe_unused tv_t *notnow, char *by, |
|
|
|
|
|
|
|
char *code, char *inet, tv_t *cd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool igndup = false; |
|
|
|
bool igndup = false; |
|
|
|
|
|
|
|
|
|
|
@ -5836,11 +5926,12 @@ static char *cmd_poolstats(char *cmd, char *id, __maybe_unused tv_t *notnow, |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return cmd_poolstats_do(cmd, id, by, code, inet, cd, igndup); |
|
|
|
return cmd_poolstats_do(conn, cmd, id, by, code, inet, cd, igndup); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_userstats(char *cmd, char *id, __maybe_unused tv_t *notnow, |
|
|
|
static char *cmd_userstats(__maybe_unused PGconn *conn, char *cmd, char *id, |
|
|
|
char *by, char *code, char *inet, tv_t *cd) |
|
|
|
__maybe_unused tv_t *notnow, char *by, char *code, |
|
|
|
|
|
|
|
char *inet, tv_t *cd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char reply[1024] = ""; |
|
|
|
char reply[1024] = ""; |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
size_t siz = sizeof(reply); |
|
|
@ -5917,8 +6008,8 @@ static char *cmd_userstats(char *cmd, char *id, __maybe_unused tv_t *notnow, |
|
|
|
return strdup(reply); |
|
|
|
return strdup(reply); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_newid(char *cmd, char *id, tv_t *now, char *by, char *code, char *inet, |
|
|
|
static char *cmd_newid(PGconn *conn, char *cmd, char *id, tv_t *now, char *by, |
|
|
|
__maybe_unused tv_t *cd) |
|
|
|
char *code, char *inet, __maybe_unused tv_t *cd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char reply[1024] = ""; |
|
|
|
char reply[1024] = ""; |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
size_t siz = sizeof(reply); |
|
|
@ -5928,8 +6019,8 @@ static char *cmd_newid(char *cmd, char *id, tv_t *now, char *by, char *code, cha |
|
|
|
int par; |
|
|
|
int par; |
|
|
|
bool ok = false; |
|
|
|
bool ok = false; |
|
|
|
ExecStatusType rescode; |
|
|
|
ExecStatusType rescode; |
|
|
|
|
|
|
|
bool conned = false; |
|
|
|
PGresult *res; |
|
|
|
PGresult *res; |
|
|
|
PGconn *conn; |
|
|
|
|
|
|
|
char *ins; |
|
|
|
char *ins; |
|
|
|
int n; |
|
|
|
int n; |
|
|
|
|
|
|
|
|
|
|
@ -5962,7 +6053,10 @@ static char *cmd_newid(char *cmd, char *id, tv_t *now, char *by, char *code, cha |
|
|
|
ins = "insert into idcontrol " |
|
|
|
ins = "insert into idcontrol " |
|
|
|
"(idname,lastid" MODIFYDATECONTROL ") values (" PQPARAM10 ")"; |
|
|
|
"(idname,lastid" MODIFYDATECONTROL ") values (" PQPARAM10 ")"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!conn) { |
|
|
|
conn = dbconnect(); |
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
conned = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0); |
|
|
|
res = PQexecParams(conn, ins, par, NULL, (const char **)params, NULL, NULL, 0); |
|
|
|
rescode = PQresultStatus(res); |
|
|
|
rescode = PQresultStatus(res); |
|
|
@ -5974,6 +6068,7 @@ static char *cmd_newid(char *cmd, char *id, tv_t *now, char *by, char *code, cha |
|
|
|
ok = true; |
|
|
|
ok = true; |
|
|
|
foil: |
|
|
|
foil: |
|
|
|
PQclear(res); |
|
|
|
PQclear(res); |
|
|
|
|
|
|
|
if (conned) |
|
|
|
PQfinish(conn); |
|
|
|
PQfinish(conn); |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
for (n = 0; n < par; n++) |
|
|
|
free(params[n]); |
|
|
|
free(params[n]); |
|
|
@ -5992,7 +6087,8 @@ foil: |
|
|
|
return strdup(reply); |
|
|
|
return strdup(reply); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_payments(char *cmd, char *id, __maybe_unused tv_t *now, __maybe_unused char *by, |
|
|
|
static char *cmd_payments(__maybe_unused PGconn *conn, char *cmd, char *id, |
|
|
|
|
|
|
|
__maybe_unused 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) |
|
|
|
__maybe_unused tv_t *notcd) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -6047,7 +6143,8 @@ static char *cmd_payments(char *cmd, char *id, __maybe_unused tv_t *now, __maybe |
|
|
|
return buf; |
|
|
|
return buf; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_workers(char *cmd, char *id, __maybe_unused tv_t *now, __maybe_unused char *by, |
|
|
|
static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id, |
|
|
|
|
|
|
|
__maybe_unused 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) |
|
|
|
__maybe_unused tv_t *notcd) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -6184,7 +6281,8 @@ static char *cmd_workers(char *cmd, char *id, __maybe_unused tv_t *now, __maybe_ |
|
|
|
return buf; |
|
|
|
return buf; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_allusers(char *cmd, char *id, __maybe_unused tv_t *now, __maybe_unused char *by, |
|
|
|
static char *cmd_allusers(__maybe_unused PGconn *conn, char *cmd, char *id, |
|
|
|
|
|
|
|
__maybe_unused 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) |
|
|
|
__maybe_unused tv_t *notcd) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -6289,12 +6387,12 @@ static char *cmd_allusers(char *cmd, char *id, __maybe_unused tv_t *now, __maybe |
|
|
|
return buf; |
|
|
|
return buf; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_sharelog(char *cmd, char *id, __maybe_unused tv_t *notnow, |
|
|
|
static char *cmd_sharelog(PGconn *conn, char *cmd, char *id, |
|
|
|
char *by, char *code, char *inet, tv_t *cd) |
|
|
|
__maybe_unused tv_t *notnow, char *by, |
|
|
|
|
|
|
|
char *code, char *inet, tv_t *cd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char reply[1024] = ""; |
|
|
|
char reply[1024] = ""; |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
PGconn *conn; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// log to logfile with processing success/failure code
|
|
|
|
// log to logfile with processing success/failure code
|
|
|
|
|
|
|
|
|
|
|
@ -6358,7 +6456,6 @@ static char *cmd_sharelog(char *cmd, char *id, __maybe_unused tv_t *notnow, |
|
|
|
if (!i_reward) |
|
|
|
if (!i_reward) |
|
|
|
return strdup(reply); |
|
|
|
return strdup(reply); |
|
|
|
|
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
workinfoid = workinfo_add(conn, DATA_TRANSFER(i_workinfoid)->data, |
|
|
|
workinfoid = workinfo_add(conn, DATA_TRANSFER(i_workinfoid)->data, |
|
|
|
DATA_TRANSFER(i_poolinstance)->data, |
|
|
|
DATA_TRANSFER(i_poolinstance)->data, |
|
|
|
DATA_TRANSFER(i_transactiontree)->data, |
|
|
|
DATA_TRANSFER(i_transactiontree)->data, |
|
|
@ -6371,7 +6468,6 @@ static char *cmd_sharelog(char *cmd, char *id, __maybe_unused tv_t *notnow, |
|
|
|
DATA_TRANSFER(i_ntime)->data, |
|
|
|
DATA_TRANSFER(i_ntime)->data, |
|
|
|
DATA_TRANSFER(i_reward)->data, |
|
|
|
DATA_TRANSFER(i_reward)->data, |
|
|
|
by, code, inet, cd, igndup); |
|
|
|
by, code, inet, cd, igndup); |
|
|
|
PQfinish(conn); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (workinfoid == -1) { |
|
|
|
if (workinfoid == -1) { |
|
|
|
LOGERR("%s.failed.DBE", id); |
|
|
|
LOGERR("%s.failed.DBE", id); |
|
|
@ -6431,7 +6527,7 @@ static char *cmd_sharelog(char *cmd, char *id, __maybe_unused tv_t *notnow, |
|
|
|
if (!i_secondaryuserid) |
|
|
|
if (!i_secondaryuserid) |
|
|
|
return strdup(reply); |
|
|
|
return strdup(reply); |
|
|
|
|
|
|
|
|
|
|
|
ok = shares_add(DATA_TRANSFER(i_workinfoid)->data, |
|
|
|
ok = shares_add(conn, DATA_TRANSFER(i_workinfoid)->data, |
|
|
|
DATA_TRANSFER(i_username)->data, |
|
|
|
DATA_TRANSFER(i_username)->data, |
|
|
|
DATA_TRANSFER(i_workername)->data, |
|
|
|
DATA_TRANSFER(i_workername)->data, |
|
|
|
DATA_TRANSFER(i_clientid)->data, |
|
|
|
DATA_TRANSFER(i_clientid)->data, |
|
|
@ -6489,7 +6585,7 @@ static char *cmd_sharelog(char *cmd, char *id, __maybe_unused tv_t *notnow, |
|
|
|
if (!i_secondaryuserid) |
|
|
|
if (!i_secondaryuserid) |
|
|
|
return strdup(reply); |
|
|
|
return strdup(reply); |
|
|
|
|
|
|
|
|
|
|
|
ok = shareerrors_add(DATA_TRANSFER(i_workinfoid)->data, |
|
|
|
ok = shareerrors_add(conn, DATA_TRANSFER(i_workinfoid)->data, |
|
|
|
DATA_TRANSFER(i_username)->data, |
|
|
|
DATA_TRANSFER(i_username)->data, |
|
|
|
DATA_TRANSFER(i_workername)->data, |
|
|
|
DATA_TRANSFER(i_workername)->data, |
|
|
|
DATA_TRANSFER(i_clientid)->data, |
|
|
|
DATA_TRANSFER(i_clientid)->data, |
|
|
@ -6521,7 +6617,7 @@ static char *cmd_sharelog(char *cmd, char *id, __maybe_unused tv_t *notnow, |
|
|
|
if (!i_poolinstance) |
|
|
|
if (!i_poolinstance) |
|
|
|
return strdup(reply); |
|
|
|
return strdup(reply); |
|
|
|
|
|
|
|
|
|
|
|
ok = workinfo_age(NULL, DATA_TRANSFER(i_workinfoid)->data, |
|
|
|
ok = workinfo_age(conn, DATA_TRANSFER(i_workinfoid)->data, |
|
|
|
DATA_TRANSFER(i_poolinstance)->data, |
|
|
|
DATA_TRANSFER(i_poolinstance)->data, |
|
|
|
by, code, inet, cd); |
|
|
|
by, code, inet, cd); |
|
|
|
|
|
|
|
|
|
|
@ -6543,12 +6639,11 @@ static char *cmd_sharelog(char *cmd, char *id, __maybe_unused tv_t *notnow, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: the confirm update: identify block changes from workinfo height?
|
|
|
|
// TODO: the confirm update: identify block changes from workinfo height?
|
|
|
|
static char *cmd_blocks_do(char *cmd, char *id, char *by, char *code, char *inet, |
|
|
|
static char *cmd_blocks_do(PGconn *conn, char *cmd, char *id, char *by, |
|
|
|
tv_t *cd, bool igndup) |
|
|
|
char *code, char *inet, tv_t *cd, bool igndup) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char reply[1024] = ""; |
|
|
|
char reply[1024] = ""; |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
PGconn *conn; |
|
|
|
|
|
|
|
K_ITEM *i_height, *i_blockhash, *i_confirmed, *i_workinfoid, *i_username; |
|
|
|
K_ITEM *i_height, *i_blockhash, *i_confirmed, *i_workinfoid, *i_username; |
|
|
|
K_ITEM *i_workername, *i_clientid, *i_enonce1, *i_nonce2, *i_nonce, *i_reward; |
|
|
|
K_ITEM *i_workername, *i_clientid, *i_enonce1, *i_nonce2, *i_nonce, *i_reward; |
|
|
|
char *msg; |
|
|
|
char *msg; |
|
|
@ -6604,7 +6699,6 @@ static char *cmd_blocks_do(char *cmd, char *id, char *by, char *code, char *inet |
|
|
|
return strdup(reply); |
|
|
|
return strdup(reply); |
|
|
|
|
|
|
|
|
|
|
|
msg = "added"; |
|
|
|
msg = "added"; |
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
ok = blocks_add(conn, DATA_TRANSFER(i_height)->data, |
|
|
|
ok = blocks_add(conn, DATA_TRANSFER(i_height)->data, |
|
|
|
DATA_TRANSFER(i_blockhash)->data, |
|
|
|
DATA_TRANSFER(i_blockhash)->data, |
|
|
|
DATA_TRANSFER(i_confirmed)->data, |
|
|
|
DATA_TRANSFER(i_confirmed)->data, |
|
|
@ -6620,7 +6714,6 @@ static char *cmd_blocks_do(char *cmd, char *id, char *by, char *code, char *inet |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BLOCKS_CONFIRM: |
|
|
|
case BLOCKS_CONFIRM: |
|
|
|
msg = "confirmed"; |
|
|
|
msg = "confirmed"; |
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
ok = blocks_add(conn, DATA_TRANSFER(i_height)->data, |
|
|
|
ok = blocks_add(conn, DATA_TRANSFER(i_height)->data, |
|
|
|
DATA_TRANSFER(i_blockhash)->data, |
|
|
|
DATA_TRANSFER(i_blockhash)->data, |
|
|
|
DATA_TRANSFER(i_confirmed)->data, |
|
|
|
DATA_TRANSFER(i_confirmed)->data, |
|
|
@ -6634,8 +6727,6 @@ static char *cmd_blocks_do(char *cmd, char *id, char *by, char *code, char *inet |
|
|
|
return strdup("failed.DATA"); |
|
|
|
return strdup("failed.DATA"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PQfinish(conn); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ok) { |
|
|
|
if (!ok) { |
|
|
|
LOGERR("%s.failed.DBE", id); |
|
|
|
LOGERR("%s.failed.DBE", id); |
|
|
|
return strdup("failed.DBE"); |
|
|
|
return strdup("failed.DBE"); |
|
|
@ -6646,8 +6737,9 @@ static char *cmd_blocks_do(char *cmd, char *id, char *by, char *code, char *inet |
|
|
|
return strdup(reply); |
|
|
|
return strdup(reply); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_blocks(char *cmd, char *id, __maybe_unused tv_t *notnow, |
|
|
|
static char *cmd_blocks(PGconn *conn, char *cmd, char *id, |
|
|
|
char *by, char *code, char *inet, tv_t *cd) |
|
|
|
__maybe_unused tv_t *notnow, char *by, |
|
|
|
|
|
|
|
char *code, char *inet, tv_t *cd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool igndup = false; |
|
|
|
bool igndup = false; |
|
|
|
|
|
|
|
|
|
|
@ -6658,15 +6750,14 @@ static char *cmd_blocks(char *cmd, char *id, __maybe_unused tv_t *notnow, |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return cmd_blocks_do(cmd, id, by, code, inet, cd, igndup); |
|
|
|
return cmd_blocks_do(conn, cmd, id, by, code, inet, cd, igndup); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_auth_do(char *cmd, char *id, __maybe_unused tv_t *now, char *by, |
|
|
|
static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, |
|
|
|
char *code, char *inet, tv_t *cd, bool igndup) |
|
|
|
char *code, char *inet, tv_t *cd, bool igndup) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char reply[1024] = ""; |
|
|
|
char reply[1024] = ""; |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
PGconn *conn; |
|
|
|
|
|
|
|
K_ITEM *i_poolinstance, *i_username, *i_workername, *i_clientid; |
|
|
|
K_ITEM *i_poolinstance, *i_username, *i_workername, *i_clientid; |
|
|
|
K_ITEM *i_enonce1, *i_useragent; |
|
|
|
K_ITEM *i_enonce1, *i_useragent; |
|
|
|
char *secuserid; |
|
|
|
char *secuserid; |
|
|
@ -6697,7 +6788,6 @@ static char *cmd_auth_do(char *cmd, char *id, __maybe_unused tv_t *now, char *by |
|
|
|
if (!i_useragent) |
|
|
|
if (!i_useragent) |
|
|
|
return strdup(reply); |
|
|
|
return strdup(reply); |
|
|
|
|
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
secuserid = auths_add(conn, DATA_TRANSFER(i_poolinstance)->data, |
|
|
|
secuserid = auths_add(conn, DATA_TRANSFER(i_poolinstance)->data, |
|
|
|
DATA_TRANSFER(i_username)->data, |
|
|
|
DATA_TRANSFER(i_username)->data, |
|
|
|
DATA_TRANSFER(i_workername)->data, |
|
|
|
DATA_TRANSFER(i_workername)->data, |
|
|
@ -6705,7 +6795,6 @@ static char *cmd_auth_do(char *cmd, char *id, __maybe_unused tv_t *now, char *by |
|
|
|
DATA_TRANSFER(i_enonce1)->data, |
|
|
|
DATA_TRANSFER(i_enonce1)->data, |
|
|
|
DATA_TRANSFER(i_useragent)->data, |
|
|
|
DATA_TRANSFER(i_useragent)->data, |
|
|
|
by, code, inet, cd, igndup); |
|
|
|
by, code, inet, cd, igndup); |
|
|
|
PQfinish(conn); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!secuserid) { |
|
|
|
if (!secuserid) { |
|
|
|
LOGDEBUG("%s.failed.DBE", id); |
|
|
|
LOGDEBUG("%s.failed.DBE", id); |
|
|
@ -6717,7 +6806,8 @@ static char *cmd_auth_do(char *cmd, char *id, __maybe_unused tv_t *now, char *by |
|
|
|
return strdup(reply); |
|
|
|
return strdup(reply); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_auth(char *cmd, char *id, tv_t *now, char *by, |
|
|
|
static char *cmd_auth(PGconn *conn, char *cmd, char *id, |
|
|
|
|
|
|
|
__maybe_unused tv_t *now, char *by, |
|
|
|
char *code, char *inet, tv_t *cd) |
|
|
|
char *code, char *inet, tv_t *cd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool igndup = false; |
|
|
|
bool igndup = false; |
|
|
@ -6729,10 +6819,11 @@ static char *cmd_auth(char *cmd, char *id, tv_t *now, char *by, |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return cmd_auth_do(cmd, id, now, by, code, inet, cd, igndup); |
|
|
|
return cmd_auth_do(conn, cmd, id, by, code, inet, cd, igndup); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_homepage(char *cmd, char *id, __maybe_unused tv_t *now, __maybe_unused char *by, |
|
|
|
static char *cmd_homepage(__maybe_unused PGconn *conn, char *cmd, char *id, |
|
|
|
|
|
|
|
__maybe_unused 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) |
|
|
|
__maybe_unused tv_t *notcd) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -6868,7 +6959,8 @@ static char *cmd_homepage(char *cmd, char *id, __maybe_unused tv_t *now, __maybe |
|
|
|
return buf; |
|
|
|
return buf; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_dsp(char *cmd, char *id, __maybe_unused tv_t *now, |
|
|
|
static char *cmd_dsp(__maybe_unused PGconn *conn, __maybe_unused char *cmd, |
|
|
|
|
|
|
|
char *id, __maybe_unused tv_t *now, |
|
|
|
__maybe_unused char *by, __maybe_unused char *code, |
|
|
|
__maybe_unused char *by, __maybe_unused char *code, |
|
|
|
__maybe_unused char *inet, __maybe_unused tv_t *notcd) |
|
|
|
__maybe_unused char *inet, __maybe_unused tv_t *notcd) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -6897,9 +6989,10 @@ static char *cmd_dsp(char *cmd, char *id, __maybe_unused tv_t *now, |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_stats(char *cmd, char *id, __maybe_unused tv_t *now, |
|
|
|
static char *cmd_stats(__maybe_unused PGconn *conn, char *cmd, char *id, |
|
|
|
__maybe_unused char *by, __maybe_unused char *code, |
|
|
|
__maybe_unused tv_t *now, __maybe_unused char *by, |
|
|
|
__maybe_unused char *inet, __maybe_unused tv_t *notcd) |
|
|
|
__maybe_unused char *code, __maybe_unused char *inet, |
|
|
|
|
|
|
|
__maybe_unused tv_t *notcd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char tmp[1024], *buf; |
|
|
|
char tmp[1024], *buf; |
|
|
|
size_t len, off; |
|
|
|
size_t len, off; |
|
|
@ -6987,7 +7080,7 @@ static struct CMDS { |
|
|
|
char *cmd_str; |
|
|
|
char *cmd_str; |
|
|
|
bool noid; // doesn't require an id
|
|
|
|
bool noid; // doesn't require an id
|
|
|
|
bool createdate; // requires a createdate
|
|
|
|
bool createdate; // requires a createdate
|
|
|
|
char *(*func)(char *, char *, tv_t *, char *, char *, char *, tv_t *); |
|
|
|
char *(*func)(PGconn *, char *, char *, tv_t *, char *, char *, char *, tv_t *); |
|
|
|
char *access; |
|
|
|
char *access; |
|
|
|
} cmds[] = { |
|
|
|
} cmds[] = { |
|
|
|
{ CMD_SHUTDOWN, "shutdown", true, false, NULL, ACCESS_SYSTEM }, |
|
|
|
{ CMD_SHUTDOWN, "shutdown", true, false, NULL, ACCESS_SYSTEM }, |
|
|
@ -7425,7 +7518,7 @@ static void *summariser(__maybe_unused void *arg) |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void reload_line(char *filename, uint64_t count, char *buf) |
|
|
|
static void reload_line(PGconn *conn, char *filename, uint64_t count, char *buf) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char cmd[CMD_SIZ+1], id[ID_SIZ+1]; |
|
|
|
char cmd[CMD_SIZ+1], id[ID_SIZ+1]; |
|
|
|
enum cmd_values cmdnum; |
|
|
|
enum cmd_values cmdnum; |
|
|
@ -7475,7 +7568,8 @@ static void reload_line(char *filename, uint64_t count, char *buf) |
|
|
|
case CMD_POOLSTAT: |
|
|
|
case CMD_POOLSTAT: |
|
|
|
case CMD_USERSTAT: |
|
|
|
case CMD_USERSTAT: |
|
|
|
case CMD_BLOCK: |
|
|
|
case CMD_BLOCK: |
|
|
|
ans = cmds[which_cmds].func(cmd, id, &now, (char *)"code", |
|
|
|
ans = cmds[which_cmds].func(conn, cmd, id, &now, |
|
|
|
|
|
|
|
(char *)"code", |
|
|
|
(char *)__func__, |
|
|
|
(char *)__func__, |
|
|
|
(char *)"127.0.0.1", &cd); |
|
|
|
(char *)"127.0.0.1", &cd); |
|
|
|
if (ans) |
|
|
|
if (ans) |
|
|
@ -7513,6 +7607,7 @@ static void reload_line(char *filename, uint64_t count, char *buf) |
|
|
|
* when ckdb aborts at the beginning of the reload */ |
|
|
|
* when ckdb aborts at the beginning of the reload */ |
|
|
|
static void reload_from(tv_t *start) |
|
|
|
static void reload_from(tv_t *start) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
PGconn *conn = NULL; |
|
|
|
char buf[DATE_BUFSIZ+1], run[DATE_BUFSIZ+1]; |
|
|
|
char buf[DATE_BUFSIZ+1], run[DATE_BUFSIZ+1]; |
|
|
|
size_t rflen = strlen(restorefrom); |
|
|
|
size_t rflen = strlen(restorefrom); |
|
|
|
char *missingfirst = NULL, *missinglast = NULL; |
|
|
|
char *missingfirst = NULL, *missinglast = NULL; |
|
|
@ -7540,6 +7635,8 @@ static void reload_from(tv_t *start) |
|
|
|
snprintf(data, sizeof(data), "reload.%s.s0", run); |
|
|
|
snprintf(data, sizeof(data), "reload.%s.s0", run); |
|
|
|
LOGFILE(data); |
|
|
|
LOGFILE(data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
conn = dbconnect(); |
|
|
|
|
|
|
|
|
|
|
|
total = 0; |
|
|
|
total = 0; |
|
|
|
processing = 0; |
|
|
|
processing = 0; |
|
|
|
while (!finished) { |
|
|
|
while (!finished) { |
|
|
@ -7548,7 +7645,7 @@ static void reload_from(tv_t *start) |
|
|
|
count = 0; |
|
|
|
count = 0; |
|
|
|
|
|
|
|
|
|
|
|
while (fgets_unlocked(data, MAX_READ, fp)) |
|
|
|
while (fgets_unlocked(data, MAX_READ, fp)) |
|
|
|
reload_line(filename, ++count, data); |
|
|
|
reload_line(conn, filename, ++count, data); |
|
|
|
|
|
|
|
|
|
|
|
if (ferror(fp)) { |
|
|
|
if (ferror(fp)) { |
|
|
|
int err = errno; |
|
|
|
int err = errno; |
|
|
@ -7609,6 +7706,8 @@ static void reload_from(tv_t *start) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PQfinish(conn); |
|
|
|
|
|
|
|
|
|
|
|
snprintf(data, sizeof(data), "reload.%s.%"PRIu64, run, total); |
|
|
|
snprintf(data, sizeof(data), "reload.%s.%"PRIu64, run, total); |
|
|
|
LOGFILE(data); |
|
|
|
LOGFILE(data); |
|
|
|
LOGWARNING("%s(): read %d file%s, total %"PRIu64" line%s", |
|
|
|
LOGWARNING("%s(): read %d file%s, total %"PRIu64" line%s", |
|
|
@ -7734,7 +7833,8 @@ static void *listener(void *arg) |
|
|
|
if (dup) |
|
|
|
if (dup) |
|
|
|
send_unix_msg(sockd, last_reply); |
|
|
|
send_unix_msg(sockd, last_reply); |
|
|
|
else { |
|
|
|
else { |
|
|
|
ans = cmds[which_cmds].func(cmd, id, &now, (char *)"code", |
|
|
|
ans = cmds[which_cmds].func(NULL, cmd, id, &now, |
|
|
|
|
|
|
|
(char *)"code", |
|
|
|
(char *)__func__, |
|
|
|
(char *)__func__, |
|
|
|
(char *)"127.0.0.1", &cd); |
|
|
|
(char *)"127.0.0.1", &cd); |
|
|
|
siz = strlen(ans) + strlen(id) + 32; |
|
|
|
siz = strlen(ans) + strlen(id) + 32; |
|
|
|