Browse Source

api: pool query (uptime, ping, discon., url and user)

master
Tanguy Pruvot 10 years ago
parent
commit
7e15f31706
  1. 26
      api.cpp
  2. 12
      ccminer.cpp
  3. 2
      hashlog.cpp
  4. 5
      miner.h
  5. 2
      util.cpp

26
api.cpp

@ -110,6 +110,8 @@ extern int device_map[8]; @@ -110,6 +110,8 @@ extern int device_map[8];
extern char *device_name[8];
extern int num_cpus;
extern char driver_version[32];
extern struct stratum_ctx stratum;
extern char* rpc_user;
// sysinfos.cpp
extern float cpu_temp(int);
@ -208,12 +210,34 @@ static char *getsummary(char *params) @@ -208,12 +210,34 @@ static char *getsummary(char *params)
}
/**
* Returns current pool infos
* Returns some infos about current pool
*/
static char *getpoolnfo(char *params)
{
char *p = buffer;
char jobid[128] = { 0 };
char nonce[128] = { 0 };
*p = '\0';
if (!stratum.url) {
sprintf(p, "|");
return p;
}
if (stratum.job.job_id)
strncpy(jobid, stratum.job.job_id, sizeof(stratum.job.job_id));
if (stratum.job.xnonce2) {
/* used temporary to be sure all is ok */
cbin2hex(nonce, (const char*) stratum.job.xnonce2, stratum.xnonce2_size);
}
sprintf(p, "URL=%s;USER=%s;H=%u;JOB=%s;DIFF=%.6f;N2SZ=%zd;N2=0x%s;PING=%u;DISCO=%u;UPTIME=%u|",
stratum.url, rpc_user ? rpc_user : "",
stratum.job.height, jobid, stratum.job.diff,
stratum.xnonce2_size, nonce, stratum.answer_msec,
stratum.disconnects, (uint32_t) (time(NULL) - stratum.tm_connected));
return p;
}

12
ccminer.cpp

@ -211,9 +211,10 @@ int num_processors; @@ -211,9 +211,10 @@ int num_processors;
int device_map[8] = {0,1,2,3,4,5,6,7}; // CB
char *device_name[8]; // CB
int device_sm[8];
char *rpc_user = NULL;
static char *rpc_url;
static char *rpc_userpass;
static char *rpc_user, *rpc_pass;
static char *rpc_pass;
static char *short_url = NULL;
char *opt_cert;
char *opt_proxy;
@ -226,7 +227,7 @@ int stratum_thr_id = -1; @@ -226,7 +227,7 @@ int stratum_thr_id = -1;
int api_thr_id = -1;
bool stratum_need_reset = false;
struct work_restart *work_restart = NULL;
static struct stratum_ctx stratum;
struct stratum_ctx stratum = { 0 };
pthread_mutex_t applog_lock;
static pthread_mutex_t stats_lock;
@ -602,6 +603,7 @@ static bool submit_upstream_work(CURL *curl, struct work *work) @@ -602,6 +603,7 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
free(ntimestr);
free(noncestr);
gettimeofday(&stratum.tv_submit, NULL);
if (unlikely(!stratum_send_line(&stratum, s))) {
applog(LOG_ERR, "submit_upstream_work stratum_send_line failed");
return false;
@ -1503,6 +1505,7 @@ static bool stratum_handle_response(char *buf) @@ -1503,6 +1505,7 @@ static bool stratum_handle_response(char *buf)
{
json_t *val, *err_val, *res_val, *id_val;
json_error_t err;
struct timeval tv_answer, diff;
bool ret = false;
val = JSON_LOADS(buf, &err);
@ -1522,6 +1525,11 @@ static bool stratum_handle_response(char *buf) @@ -1522,6 +1525,11 @@ static bool stratum_handle_response(char *buf)
if (json_integer_value(id_val) < 4)
goto out;
gettimeofday(&tv_answer, NULL);
timeval_subtract(&diff, &tv_answer, &stratum.tv_submit);
// store time required to the pool to answer to a submit
stratum.answer_msec = (1000.0 * diff.tv_sec) + (uint32_t) (0.001 * diff.tv_usec);
share_result(json_is_true(res_val),
err_val ? json_string_value(json_array_get(err_val, 1)) : NULL);

2
hashlog.cpp

@ -92,7 +92,7 @@ void hashlog_remember_scan_range(struct work* work) @@ -92,7 +92,7 @@ void hashlog_remember_scan_range(struct work* work)
data = tlastshares[key];
if (range == 0) {
memset(&data, 0, sizeof(data));
data.njobid = njobid;
data.njobid = (uint32_t) njobid;
} else {
// get min and max from all sent records
data.scanned_from = LO_DWORD(range);

5
miner.h

@ -546,6 +546,11 @@ struct stratum_ctx { @@ -546,6 +546,11 @@ struct stratum_ctx {
struct stratum_job job;
pthread_mutex_t work_lock;
struct timeval tv_submit;
uint32_t answer_msec;
uint32_t disconnects;
time_t tm_connected;
int srvtime_diff;
};

2
util.cpp

@ -875,6 +875,7 @@ void stratum_disconnect(struct stratum_ctx *sctx) @@ -875,6 +875,7 @@ void stratum_disconnect(struct stratum_ctx *sctx)
{
pthread_mutex_lock(&sctx->sock_lock);
if (sctx->curl) {
sctx->disconnects++;
curl_easy_cleanup(sctx->curl);
sctx->curl = NULL;
sctx->sockbuf[0] = '\0';
@ -1080,6 +1081,7 @@ bool stratum_authorize(struct stratum_ctx *sctx, const char *user, const char *p @@ -1080,6 +1081,7 @@ bool stratum_authorize(struct stratum_ctx *sctx, const char *user, const char *p
goto out;
}
sctx->tm_connected = time(NULL);
ret = true;
// subscribe to extranonce (optional)

Loading…
Cancel
Save