Browse Source

ckdb - implement ovents

master
kanoi 9 years ago
parent
commit
eadb28c76d
  1. 6
      src/ckdb.h
  2. 62
      src/ckdb_cmd.c
  3. 4
      src/ckdb_data.c

6
src/ckdb.h

@ -51,7 +51,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.4" #define DB_VERSION "1.0.4"
#define CKDB_VERSION DB_VERSION"-1.957" #define CKDB_VERSION DB_VERSION"-1.958"
#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__
@ -2143,6 +2143,8 @@ extern double ovent_limits_ipc_factor;
// maximum lifetime of all o_limits - set by code // maximum lifetime of all o_limits - set by code
extern int o_limits_max_lifetime; extern int o_limits_max_lifetime;
#define APIKEY "KAPIKey"
// AUTHS authorise.id.json={...} // AUTHS authorise.id.json={...}
typedef struct auths { typedef struct auths {
int64_t authid; int64_t authid;
@ -3078,6 +3080,8 @@ extern void ips_add(char *group, char *ip, char *eventname, bool is_event,
char *des, bool log, bool cclass, int life, bool locked); char *des, bool log, bool cclass, int life, bool locked);
extern int _events_add(int id, char *by, char *inet, tv_t *cd, K_TREE *trf_root); extern int _events_add(int id, char *by, char *inet, tv_t *cd, K_TREE *trf_root);
#define events_add(_id, _trf_root) _events_add(_id, NULL, NULL, NULL, _trf_root) #define events_add(_id, _trf_root) _events_add(_id, NULL, NULL, NULL, _trf_root)
extern int _ovents_add(int id, char *by, char *inet, tv_t *cd, K_TREE *trf_root);
#define ovents_add(_id, _trf_root) _ovents_add(_id, NULL, NULL, NULL, _trf_root)
extern bool 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,

62
src/ckdb_cmd.c

@ -794,6 +794,7 @@ static char *cmd_workerset(PGconn *conn, char *cmd, char *id, tv_t *now,
USERATTS *useratts; USERATTS *useratts;
WORKERS *workers; WORKERS *workers;
USERS *users; USERS *users;
int ovent = OVENT_OK, done;
int32_t difficultydefault; int32_t difficultydefault;
char *reason = NULL; char *reason = NULL;
char *answer = NULL; char *answer = NULL;
@ -802,6 +803,12 @@ static char *cmd_workerset(PGconn *conn, char *cmd, char *id, tv_t *now,
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
ovent = ovents_add(OVENTID_WORKERS, trf_root);
if (ovent != OVENT_OK) {
snprintf(reply, siz, "ERR");
return reply_ovent(ovent, reply);
}
i_username = require_name(trf_root, "username", MIN_USERNAME, i_username = require_name(trf_root, "username", MIN_USERNAME,
(char *)userpatt, reply, siz); (char *)userpatt, reply, siz);
if (!i_username) { if (!i_username) {
@ -854,6 +861,7 @@ static char *cmd_workerset(PGconn *conn, char *cmd, char *id, tv_t *now,
goto kazuki; goto kazuki;
} }
done = 0;
// Loop through the list of workers and do any changes // Loop through the list of workers and do any changes
for (workernum = 0; workernum < 9999; workernum++) { for (workernum = 0; workernum < 9999; workernum++) {
snprintf(workername_buf, sizeof(workername_buf), snprintf(workername_buf, sizeof(workername_buf),
@ -864,6 +872,17 @@ static char *cmd_workerset(PGconn *conn, char *cmd, char *id, tv_t *now,
if (!i_workername) if (!i_workername)
break; break;
// More than 1?
if (done++ == 1) {
ovent = ovents_add(OVENTID_MULTIADDR, trf_root);
if (ovent != OVENT_OK) {
if (answer)
free(answer);
snprintf(reply, siz, "ERR");
return reply_ovent(ovent, reply);
}
}
w_item = find_workers(false, users->userid, w_item = find_workers(false, users->userid,
transfer_data(i_workername)); transfer_data(i_workername));
// Abort if any dont exist // Abort if any dont exist
@ -928,6 +947,16 @@ static char *cmd_workerset(PGconn *conn, char *cmd, char *id, tv_t *now,
K_WUNLOCK(heartbeatqueue_free); K_WUNLOCK(heartbeatqueue_free);
} }
} }
// Only 1?
if (done == 1) {
ovent = ovents_add(OVENTID_ONEADDR, trf_root);
if (ovent != OVENT_OK) {
if (answer)
free(answer);
snprintf(reply, siz, "ERR");
return reply_ovent(ovent, reply);
}
}
} }
kazuki: kazuki:
@ -1236,6 +1265,7 @@ static char *cmd_blocklist(__maybe_unused PGconn *conn, char *cmd, char *id,
__maybe_unused tv_t *notcd, __maybe_unused tv_t *notcd,
__maybe_unused K_TREE *trf_root) __maybe_unused K_TREE *trf_root)
{ {
int ovent = OVENT_OK;
K_TREE_CTX ctx[1]; K_TREE_CTX ctx[1];
K_ITEM *b_item; K_ITEM *b_item;
BLOCKS *blocks; BLOCKS *blocks;
@ -1250,6 +1280,12 @@ static char *cmd_blocklist(__maybe_unused PGconn *conn, char *cmd, char *id,
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
ovent = ovents_add(OVENTID_BLOCKS, trf_root);
if (ovent != OVENT_OK) {
snprintf(tmp, sizeof(tmp), "ERR");
return reply_ovent(ovent, tmp);
}
maxrows = sys_setting(BLOCKS_SETTING_NAME, BLOCKS_DEFAULT, now); maxrows = sys_setting(BLOCKS_SETTING_NAME, BLOCKS_DEFAULT, now);
APPEND_REALLOC_INIT(buf, off, len); APPEND_REALLOC_INIT(buf, off, len);
@ -2030,6 +2066,7 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
USERSTATS *userstats; USERSTATS *userstats;
USERATTS *useratts; USERATTS *useratts;
USERS *users; USERS *users;
int ovent = OVENT_OK;
char reply[1024] = ""; char reply[1024] = "";
char tmp[1024]; char tmp[1024];
int64_t oldworkers = USER_OLD_WORKERS_DEFAULT; int64_t oldworkers = USER_OLD_WORKERS_DEFAULT;
@ -2042,6 +2079,12 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
ovent = ovents_add(OVENTID_WORKERS, trf_root);
if (ovent != OVENT_OK) {
snprintf(reply, siz, "ERR");
return reply_ovent(ovent, reply);
}
i_username = adminuser(trf_root, reply, siz); i_username = adminuser(trf_root, reply, siz);
if (!i_username) if (!i_username)
return strdup(reply); return strdup(reply);
@ -3287,6 +3330,7 @@ static char *cmd_homepage(__maybe_unused PGconn *conn, char *cmd, char *id,
{ {
K_ITEM *i_username, *u_item, *b_item, *p_item, *us_item, look; K_ITEM *i_username, *u_item, *b_item, *p_item, *us_item, look;
K_ITEM *ua_item, *pa_item; K_ITEM *ua_item, *pa_item;
int ovent = OVENT_OK;
double u_hashrate5m, u_hashrate1hr; double u_hashrate5m, u_hashrate1hr;
char reply[1024], tmp[1024], *buf; char reply[1024], tmp[1024], *buf;
size_t siz = sizeof(reply); size_t siz = sizeof(reply);
@ -3302,6 +3346,12 @@ static char *cmd_homepage(__maybe_unused PGconn *conn, char *cmd, char *id,
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
ovent = ovents_add(OVENTID_HOMEPAGE, trf_root);
if (ovent != OVENT_OK) {
snprintf(reply, siz, "ERR");
return reply_ovent(ovent, reply);
}
i_username = optional_name(trf_root, "username", 1, NULL, reply, siz); i_username = optional_name(trf_root, "username", 1, NULL, reply, siz);
APPEND_REALLOC_INIT(buf, off, len); APPEND_REALLOC_INIT(buf, off, len);
@ -3622,6 +3672,18 @@ static char *cmd_getatts(__maybe_unused PGconn *conn, char *cmd, char *id,
goto nuts; goto nuts;
} }
*(dot++) = '\0'; *(dot++) = '\0';
if (strcmp(ptr, APIKEY) == 0) {
// API request count
event = ovents_add(OVENTID_API, trf_root);
if (event != OVENT_OK) {
if (attlist)
free(attlist);
if (answer)
free(answer);
snprintf(reply, siz, "ERR");
return reply_ovent(event, reply);
}
}
K_RLOCK(useratts_free); K_RLOCK(useratts_free);
ua_item = find_useratts(users->userid, ptr); ua_item = find_useratts(users->userid, ptr);
K_RUNLOCK(useratts_free); K_RUNLOCK(useratts_free);

4
src/ckdb_data.c

@ -5118,7 +5118,7 @@ int check_ovents(int id, char *u_key, char *i_key, char *c_key, tv_t *now)
return OVENT_OK; return OVENT_OK;
} }
K_WLOCK(events_free); K_WLOCK(ovents_free);
K_RLOCK(event_limits_free); K_RLOCK(event_limits_free);
if (u_key[0]) { if (u_key[0]) {
@ -5193,7 +5193,7 @@ int check_ovents(int id, char *u_key, char *i_key, char *c_key, tv_t *now)
} }
} }
K_RUNLOCK(event_limits_free); K_RUNLOCK(event_limits_free);
K_WUNLOCK(events_free); K_WUNLOCK(ovents_free);
if (alert) { if (alert) {
LOGERR("%s() OLERT ID:%d %s Lim:%d Time:%d Life:%d '%s/%s' " LOGERR("%s() OLERT ID:%d %s Lim:%d Time:%d Life:%d '%s/%s' "
"'%s' '%s'", __func__, "'%s' '%s'", __func__,

Loading…
Cancel
Save