Implement rudimentary X-Mining-Hashrate support.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
diff --git a/cgminer.c b/cgminer.c
index 25a2a77..cbb730c 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -100,6 +100,7 @@ int opt_scantime = 60;
int opt_expiry = 120;
int opt_bench_algo = -1;
static const bool opt_time = true;
+unsigned long long global_hashrate;
#ifdef HAVE_OPENCL
int opt_dynamic_interval = 7;
@@ -3400,6 +3401,7 @@ static void hashmeter(int thr_id, struct timeval *diff,
local_secs = (double)total_diff.tv_sec + ((double)total_diff.tv_usec / 1000000.0);
decay_time(&rolling, local_mhashes_done / local_secs);
+ global_hashrate = roundl(rolling) * 1000000;
timeval_subtract(&total_diff, &total_tv_end, &total_tv_start);
total_secs = (double)total_diff.tv_sec +
diff --git a/miner.h b/miner.h
index bb56759..57fa774 100644
--- a/miner.h
+++ b/miner.h
@@ -620,6 +620,7 @@ extern unsigned int local_work;
extern unsigned int total_go, total_ro;
extern const int opt_cutofftemp;
extern int opt_log_interval;
+extern unsigned long long global_hashrate;
#ifdef HAVE_OPENCL
typedef struct {
diff --git a/util.c b/util.c
index 703be54..ffc6a70 100644
--- a/util.c
+++ b/util.c
@@ -256,17 +256,17 @@ json_t *json_rpc_call(CURL *curl, const char *url,
bool probe, bool longpoll, int *rolltime,
struct pool *pool, bool share)
{
- json_t *val, *err_val, *res_val;
- int rc;
- struct data_buffer all_data = {NULL, 0};
- struct upload_buffer upload_data;
- json_error_t err;
- struct curl_slist *headers = NULL;
- char len_hdr[64], user_agent_hdr[128];
- char curl_err_str[CURL_ERROR_SIZE];
+ char len_hdr[64], user_agent_hdr[128], *ghashrate;
long timeout = longpoll ? (60 * 60) : 60;
+ struct data_buffer all_data = {NULL, 0};
struct header_info hi = {NULL, 0, NULL};
+ char curl_err_str[CURL_ERROR_SIZE];
+ struct curl_slist *headers = NULL;
+ struct upload_buffer upload_data;
+ json_t *val, *err_val, *res_val;
bool probing = false;
+ json_error_t err;
+ int rc;
memset(&err, 0, sizeof(err));
@@ -325,6 +325,13 @@ json_t *json_rpc_call(CURL *curl, const char *url,
"Content-type: application/json");
headers = curl_slist_append(headers,
"X-Mining-Extensions: longpoll midstate rollntime submitold");
+
+ if (likely(global_hashrate)) {
+ asprintf(&ghashrate, "X-Mining-Hashrate: %llu", global_hashrate);
+ headers = curl_slist_append(headers, ghashrate);
+ free(ghashrate);
+ }
+
headers = curl_slist_append(headers, len_hdr);
headers = curl_slist_append(headers, user_agent_hdr);
headers = curl_slist_append(headers, "Expect:"); /* disable Expect hdr*/