Browse Source

ckdb - auth return json with both secuserid and diff

master
kanoi 10 years ago
parent
commit
e41d550b6f
  1. 6
      src/ckdb.h
  2. 60
      src/ckdb_cmd.c
  3. 37
      src/ckdb_dbio.c

6
src/ckdb.h

@ -52,7 +52,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "0.9.2" #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 " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #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 *blockhash, char *amount, char *by,
char *code, char *inet, tv_t *cd, K_TREE *trf_root); char *code, char *inet, tv_t *cd, K_TREE *trf_root);
extern bool miningpayouts_fill(PGconn *conn); 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 *workername, char *clientid, char *enonce1,
char *useragent, char *preauth, char *by, char *code, char *useragent, char *preauth, char *by, char *code,
char *inet, tv_t *cd, bool igndup, K_TREE *trf_root, 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 auths_fill(PGconn *conn);
extern bool poolstats_add(PGconn *conn, bool store, char *poolinstance, extern bool poolstats_add(PGconn *conn, bool store, char *poolinstance,
char *elapsed, char *users, char *workers, char *elapsed, char *users, char *workers,

60
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); size_t siz = sizeof(reply);
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, *i_preauth; K_ITEM *i_enonce1, *i_useragent, *i_preauth;
char *secuserid; USERS *users = NULL;
WORKERS *workers = NULL;
bool ok;
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); 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) if (!i_preauth)
i_preauth = &auth_preauth; i_preauth = &auth_preauth;
secuserid = auths_add(conn, transfer_data(i_poolinstance), ok = auths_add(conn, transfer_data(i_poolinstance),
transfer_data(i_username), transfer_data(i_username),
transfer_data(i_workername), transfer_data(i_workername),
transfer_data(i_clientid), transfer_data(i_clientid),
transfer_data(i_enonce1), transfer_data(i_enonce1),
transfer_data(i_useragent), transfer_data(i_useragent),
transfer_data(i_preauth), transfer_data(i_preauth),
by, code, inet, cd, igndup, trf_root, false); by, code, inet, cd, igndup, trf_root, false,
&users, &workers);
if (!secuserid) { if (!ok) {
LOGDEBUG("%s() %s.failed.DBE", __func__, id); LOGDEBUG("%s() %s.failed.DBE", __func__, id);
return strdup("failed.DBE"); return strdup("failed.DBE");
} }
LOGDEBUG("%s.ok.auth added for %s", id, secuserid); snprintf(reply, siz,
snprintf(reply, siz, "ok.%s", secuserid); "ok.auth={\"secondaryuserid\":\"%s\","
"\"difficultydefault\":%d}",
users->secondaryuserid, workers->difficultydefault);
LOGDEBUG("%s.%s", id, reply);
return strdup(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); size_t siz = sizeof(reply);
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, *i_preauth; K_ITEM *i_enonce1, *i_useragent, *i_preauth;
char *secuserid; USERS *users = NULL;
WORKERS *workers = NULL;
bool ok;
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); 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) if (!i_preauth)
return strdup(reply); return strdup(reply);
secuserid = auths_add(conn, transfer_data(i_poolinstance), ok = auths_add(conn, transfer_data(i_poolinstance),
transfer_data(i_username), transfer_data(i_username),
transfer_data(i_workername), transfer_data(i_workername),
transfer_data(i_clientid), transfer_data(i_clientid),
transfer_data(i_enonce1), transfer_data(i_enonce1),
transfer_data(i_useragent), transfer_data(i_useragent),
transfer_data(i_preauth), transfer_data(i_preauth),
by, code, inet, cd, igndup, trf_root, true); by, code, inet, cd, igndup, trf_root, true,
&users, &workers);
if (!secuserid) { if (!ok) {
LOGDEBUG("%s() %s.failed.DBE", __func__, id); LOGDEBUG("%s() %s.failed.DBE", __func__, id);
return strdup("failed.DBE"); return strdup("failed.DBE");
} }
LOGDEBUG("%s.ok.auth added for %s", id, secuserid); snprintf(reply, siz,
snprintf(reply, siz, "ok.%s", secuserid); "ok.addrauth={\"secondaryuserid\":\"%s\","
"\"difficultydefault\":%d}",
users->secondaryuserid, workers->difficultydefault);
LOGDEBUG("%s.%s", id, reply);
return strdup(reply); return strdup(reply);
} }

37
src/ckdb_dbio.c

@ -3945,24 +3945,23 @@ bool miningpayouts_fill(PGconn *conn)
return ok; 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 *workername, char *clientid, char *enonce1,
char *useragent, char *preauth, char *by, char *code, char *useragent, char *preauth, char *by, char *code,
char *inet, tv_t *cd, bool igndup, K_TREE *trf_root, char *inet, tv_t *cd, bool igndup, K_TREE *trf_root,
bool addressuser) bool addressuser, USERS **users, WORKERS **workers)
{ {
ExecStatusType rescode; ExecStatusType rescode;
bool conned = false; 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, *w_item;
char cd_buf[DATE_BUFSIZ]; char cd_buf[DATE_BUFSIZ];
USERS *users;
AUTHS *row; AUTHS *row;
char *ins; char *ins;
char *secuserid = NULL;
char *params[8 + HISTORYDATECOUNT]; char *params[8 + HISTORYDATECOUNT];
int n, par = 0; int n, par = 0;
bool ok = false;
LOGDEBUG("%s(): add", __func__); LOGDEBUG("%s(): add", __func__);
@ -3987,14 +3986,20 @@ char *auths_add(PGconn *conn, char *poolinstance, char *username,
if (!u_item) if (!u_item)
goto unitem; goto unitem;
} }
DATA_USERS(users, u_item); DATA_USERS(*users, u_item);
STRNCPY(row->poolinstance, poolinstance); 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 // since update=false, a dup will be ok and do nothing when igndup=true
new_worker(conn, false, row->userid, workername, DIFFICULTYDEFAULT_DEF_STR, w_item = new_worker(conn, false, row->userid, workername,
IDLENOTIFICATIONENABLED_DEF, IDLENOTIFICATIONTIME_DEF_STR, DIFFICULTYDEFAULT_DEF_STR,
by, code, inet, cd, trf_root); 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); STRNCPY(row->workername, workername);
TXT_TO_INT("clientid", clientid, row->clientid); TXT_TO_INT("clientid", clientid, row->clientid);
STRNCPY(row->enonce1, enonce1); STRNCPY(row->enonce1, enonce1);
@ -4018,7 +4023,9 @@ char *auths_add(PGconn *conn, char *poolinstance, char *username,
__func__, poolinstance, workername, cd_buf); __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); K_WUNLOCK(auths_free);
@ -4056,9 +4063,7 @@ char *auths_add(PGconn *conn, char *poolinstance, char *username,
PGLOGERR("Insert", rescode, conn); PGLOGERR("Insert", rescode, conn);
goto unparam; goto unparam;
} }
ok = true;
secuserid = users->secondaryuserid;
unparam: unparam:
PQclear(res); PQclear(res);
for (n = 0; n < par; n++) for (n = 0; n < par; n++)
@ -4067,7 +4072,7 @@ unitem:
if (conned) if (conned)
PQfinish(conn); PQfinish(conn);
K_WLOCK(auths_free); K_WLOCK(auths_free);
if (!secuserid) if (!ok)
k_add_head(auths_free, a_item); k_add_head(auths_free, a_item);
else { else {
auths_root = add_to_ktree(auths_root, a_item, cmp_auths); auths_root = add_to_ktree(auths_root, a_item, cmp_auths);
@ -4075,7 +4080,7 @@ unitem:
} }
K_WUNLOCK(auths_free); K_WUNLOCK(auths_free);
return secuserid; return ok;
} }
bool auths_fill(PGconn *conn) bool auths_fill(PGconn *conn)

Loading…
Cancel
Save