|
|
@@ -147,9 +147,9 @@ static size_t resp_hdr_cb(void *ptr, size_t size, size_t nmemb, void *user_data)
|
|
|
|
|
|
memcpy(val, rem, remlen); /* store value, trim trailing ws */
|
|
|
val[remlen] = 0;
|
|
|
- while ((*val) && (isspace(val[strlen(val) - 1]))) {
|
|
|
+ while ((*val) && (isspace(val[strlen(val) - 1])))
|
|
|
val[strlen(val) - 1] = 0;
|
|
|
- }
|
|
|
+
|
|
|
if (!*val) /* skip blank value */
|
|
|
goto out;
|
|
|
|
|
|
@@ -157,9 +157,9 @@ static size_t resp_hdr_cb(void *ptr, size_t size, size_t nmemb, void *user_data)
|
|
|
applog(LOG_DEBUG, "HTTP hdr(%s): %s", key, val);
|
|
|
|
|
|
if (!strcasecmp("X-Roll-Ntime", key)) {
|
|
|
- if (!strncasecmp("N", val, 1)) {
|
|
|
+ if (!strncasecmp("N", val, 1))
|
|
|
applog(LOG_DEBUG, "X-Roll-Ntime: N found");
|
|
|
- } else {
|
|
|
+ else {
|
|
|
/* Check to see if expire= is supported and if not, set
|
|
|
* the rolltime to the default scantime */
|
|
|
if (strlen(val) > 7 && !strncasecmp("expire=", val, 7))
|
|
|
@@ -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,12 @@ 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) != -1)) {
|
|
|
+ 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*/
|
|
|
@@ -372,9 +378,8 @@ json_t *json_rpc_call(CURL *curl, const char *url,
|
|
|
if (pool->hdr_path != NULL)
|
|
|
free(pool->hdr_path);
|
|
|
pool->hdr_path = hi.lp_path;
|
|
|
- } else {
|
|
|
+ } else
|
|
|
pool->hdr_path = NULL;
|
|
|
- }
|
|
|
} else if (hi.lp_path) {
|
|
|
free(hi.lp_path);
|
|
|
hi.lp_path = NULL;
|
|
|
@@ -394,6 +399,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
|
|
|
|
|
|
if (opt_protocol) {
|
|
|
char *s = json_dumps(val, JSON_INDENT(3));
|
|
|
+
|
|
|
applog(LOG_DEBUG, "JSON protocol response:\n%s", s);
|
|
|
free(s);
|
|
|
}
|
|
|
@@ -443,8 +449,8 @@ err_out:
|
|
|
|
|
|
char *bin2hex(const unsigned char *p, size_t len)
|
|
|
{
|
|
|
- unsigned int i;
|
|
|
char *s = malloc((len * 2) + 1);
|
|
|
+ unsigned int i;
|
|
|
|
|
|
if (!s)
|
|
|
return NULL;
|
|
|
@@ -485,43 +491,14 @@ bool hex2bin(unsigned char *p, const char *hexstr, size_t len)
|
|
|
return (len == 0 && *hexstr == 0) ? true : false;
|
|
|
}
|
|
|
|
|
|
-/* Subtract the `struct timeval' values X and Y,
|
|
|
- storing the result in RESULT.
|
|
|
- Return 1 if the difference is negative, otherwise 0. */
|
|
|
-
|
|
|
-int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
|
|
|
-{
|
|
|
- /* Perform the carry for the later subtraction by updating Y. */
|
|
|
- if (x->tv_usec < y->tv_usec) {
|
|
|
- int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
|
|
|
-
|
|
|
- y->tv_usec -= 1000000 * nsec;
|
|
|
- y->tv_sec += nsec;
|
|
|
- }
|
|
|
- if (x->tv_usec - y->tv_usec > 1000000) {
|
|
|
- int nsec = (x->tv_usec - y->tv_usec) / 1000000;
|
|
|
-
|
|
|
- y->tv_usec += 1000000 * nsec;
|
|
|
- y->tv_sec -= nsec;
|
|
|
- }
|
|
|
-
|
|
|
- /* Compute the time remaining to wait.
|
|
|
- * `tv_usec' is certainly positive. */
|
|
|
- result->tv_sec = x->tv_sec - y->tv_sec;
|
|
|
- result->tv_usec = x->tv_usec - y->tv_usec;
|
|
|
-
|
|
|
- /* Return 1 if result is negative. */
|
|
|
- return x->tv_sec < y->tv_sec;
|
|
|
-}
|
|
|
-
|
|
|
bool fulltest(const unsigned char *hash, const unsigned char *target)
|
|
|
{
|
|
|
unsigned char hash_swap[32], target_swap[32];
|
|
|
uint32_t *hash32 = (uint32_t *) hash_swap;
|
|
|
uint32_t *target32 = (uint32_t *) target_swap;
|
|
|
- int i;
|
|
|
- bool rc = true;
|
|
|
char *hash_str, *target_str;
|
|
|
+ bool rc = true;
|
|
|
+ int i;
|
|
|
|
|
|
swap256(hash_swap, hash);
|
|
|
swap256(target_swap, target);
|
|
|
@@ -674,10 +651,7 @@ out:
|
|
|
|
|
|
int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg)
|
|
|
{
|
|
|
- int ret;
|
|
|
-
|
|
|
- ret = pthread_create(&thr->pth, attr, start, arg);
|
|
|
- return ret;
|
|
|
+ return pthread_create(&thr->pth, attr, start, arg);
|
|
|
}
|
|
|
|
|
|
void thr_info_freeze(struct thr_info *thr)
|