diff --git a/src/ckdb.h b/src/ckdb.h index a03ba095..b2b39f53 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -52,7 +52,7 @@ #define DB_VLOCK "1" #define DB_VERSION "0.9.2" -#define CKDB_VERSION DB_VERSION"-0.406" +#define CKDB_VERSION DB_VERSION"-0.500" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -1414,11 +1414,11 @@ extern bool miningpayouts_add(PGconn *conn, char *username, char *height, char *blockhash, char *amount, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root); extern bool miningpayouts_fill(PGconn *conn); -extern char *auths_add(PGconn *conn, char *poolinstance, char *username, +extern bool auths_add(PGconn *conn, char *poolinstance, char *username, char *workername, char *clientid, char *enonce1, char *useragent, char *preauth, char *by, char *code, char *inet, tv_t *cd, bool igndup, K_TREE *trf_root, - bool addressuser); + bool addressuser, USERS **users, WORKERS **workers); extern bool auths_fill(PGconn *conn); extern bool poolstats_add(PGconn *conn, bool store, char *poolinstance, char *elapsed, char *users, char *workers, diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 77c27c4e..ebe2b3a2 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -1735,7 +1735,9 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, size_t siz = sizeof(reply); K_ITEM *i_poolinstance, *i_username, *i_workername, *i_clientid; K_ITEM *i_enonce1, *i_useragent, *i_preauth; - char *secuserid; + USERS *users = NULL; + WORKERS *workers = NULL; + bool ok; LOGDEBUG("%s(): cmd '%s'", __func__, cmd); @@ -1768,22 +1770,26 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, if (!i_preauth) i_preauth = &auth_preauth; - secuserid = auths_add(conn, transfer_data(i_poolinstance), - transfer_data(i_username), - transfer_data(i_workername), - transfer_data(i_clientid), - transfer_data(i_enonce1), - transfer_data(i_useragent), - transfer_data(i_preauth), - by, code, inet, cd, igndup, trf_root, false); + ok = auths_add(conn, transfer_data(i_poolinstance), + transfer_data(i_username), + transfer_data(i_workername), + transfer_data(i_clientid), + transfer_data(i_enonce1), + transfer_data(i_useragent), + transfer_data(i_preauth), + by, code, inet, cd, igndup, trf_root, false, + &users, &workers); - if (!secuserid) { + if (!ok) { LOGDEBUG("%s() %s.failed.DBE", __func__, id); return strdup("failed.DBE"); } - LOGDEBUG("%s.ok.auth added for %s", id, secuserid); - snprintf(reply, siz, "ok.%s", secuserid); + snprintf(reply, siz, + "ok.auth={\"secondaryuserid\":\"%s\"," + "\"difficultydefault\":%d}", + users->secondaryuserid, workers->difficultydefault); + LOGDEBUG("%s.%s", id, reply); return strdup(reply); } @@ -1813,7 +1819,9 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by, size_t siz = sizeof(reply); K_ITEM *i_poolinstance, *i_username, *i_workername, *i_clientid; K_ITEM *i_enonce1, *i_useragent, *i_preauth; - char *secuserid; + USERS *users = NULL; + WORKERS *workers = NULL; + bool ok; LOGDEBUG("%s(): cmd '%s'", __func__, cmd); @@ -1846,22 +1854,26 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by, if (!i_preauth) return strdup(reply); - secuserid = auths_add(conn, transfer_data(i_poolinstance), - transfer_data(i_username), - transfer_data(i_workername), - transfer_data(i_clientid), - transfer_data(i_enonce1), - transfer_data(i_useragent), - transfer_data(i_preauth), - by, code, inet, cd, igndup, trf_root, true); + ok = auths_add(conn, transfer_data(i_poolinstance), + transfer_data(i_username), + transfer_data(i_workername), + transfer_data(i_clientid), + transfer_data(i_enonce1), + transfer_data(i_useragent), + transfer_data(i_preauth), + by, code, inet, cd, igndup, trf_root, true, + &users, &workers); - if (!secuserid) { + if (!ok) { LOGDEBUG("%s() %s.failed.DBE", __func__, id); return strdup("failed.DBE"); } - LOGDEBUG("%s.ok.auth added for %s", id, secuserid); - snprintf(reply, siz, "ok.%s", secuserid); + snprintf(reply, siz, + "ok.addrauth={\"secondaryuserid\":\"%s\"," + "\"difficultydefault\":%d}", + users->secondaryuserid, workers->difficultydefault); + LOGDEBUG("%s.%s", id, reply); return strdup(reply); } diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index 4033f13f..cf4b23f4 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -3945,24 +3945,23 @@ bool miningpayouts_fill(PGconn *conn) return ok; } -char *auths_add(PGconn *conn, char *poolinstance, char *username, +bool auths_add(PGconn *conn, char *poolinstance, char *username, char *workername, char *clientid, char *enonce1, char *useragent, char *preauth, char *by, char *code, char *inet, tv_t *cd, bool igndup, K_TREE *trf_root, - bool addressuser) + bool addressuser, USERS **users, WORKERS **workers) { ExecStatusType rescode; bool conned = false; PGresult *res; K_TREE_CTX ctx[1]; - K_ITEM *a_item, *u_item; + K_ITEM *a_item, *u_item, *w_item; char cd_buf[DATE_BUFSIZ]; - USERS *users; AUTHS *row; char *ins; - char *secuserid = NULL; char *params[8 + HISTORYDATECOUNT]; int n, par = 0; + bool ok = false; LOGDEBUG("%s(): add", __func__); @@ -3987,14 +3986,20 @@ char *auths_add(PGconn *conn, char *poolinstance, char *username, if (!u_item) goto unitem; } - DATA_USERS(users, u_item); + DATA_USERS(*users, u_item); STRNCPY(row->poolinstance, poolinstance); - row->userid = users->userid; + row->userid = (*users)->userid; // since update=false, a dup will be ok and do nothing when igndup=true - new_worker(conn, false, row->userid, workername, DIFFICULTYDEFAULT_DEF_STR, - IDLENOTIFICATIONENABLED_DEF, IDLENOTIFICATIONTIME_DEF_STR, - by, code, inet, cd, trf_root); + w_item = new_worker(conn, false, row->userid, workername, + DIFFICULTYDEFAULT_DEF_STR, + IDLENOTIFICATIONENABLED_DEF, + IDLENOTIFICATIONTIME_DEF_STR, + by, code, inet, cd, trf_root); + if (!w_item) + goto unitem; + + DATA_WORKERS(*workers, w_item); STRNCPY(row->workername, workername); TXT_TO_INT("clientid", clientid, row->clientid); STRNCPY(row->enonce1, enonce1); @@ -4018,7 +4023,9 @@ char *auths_add(PGconn *conn, char *poolinstance, char *username, __func__, poolinstance, workername, cd_buf); } - return users->secondaryuserid; + /* Let them mine, that's what matters :) + * though this would normally only be during a reload */ + return true; } K_WUNLOCK(auths_free); @@ -4056,9 +4063,7 @@ char *auths_add(PGconn *conn, char *poolinstance, char *username, PGLOGERR("Insert", rescode, conn); goto unparam; } - - secuserid = users->secondaryuserid; - + ok = true; unparam: PQclear(res); for (n = 0; n < par; n++) @@ -4067,7 +4072,7 @@ unitem: if (conned) PQfinish(conn); K_WLOCK(auths_free); - if (!secuserid) + if (!ok) k_add_head(auths_free, a_item); else { auths_root = add_to_ktree(auths_root, a_item, cmp_auths); @@ -4075,7 +4080,7 @@ unitem: } K_WUNLOCK(auths_free); - return secuserid; + return ok; } bool auths_fill(PGconn *conn)