Browse Source

Parse the difficultydefault entry returned from authorise

master
Con Kolivas 10 years ago
parent
commit
27ac4e23ef
  1. 5
      src/ckpool.c
  2. 1
      src/ckpool.h
  3. 10
      src/libckpool.h
  4. 22
      src/stratifier.c

5
src/ckpool.c

@ -883,9 +883,10 @@ static void json_get_int64(int64_t *store, json_t *val, const char *res)
return; return;
} }
*store = json_integer_value(entry); *store = json_integer_value(entry);
LOGDEBUG("Json found entry %s: %ld", res, *store);
} }
static void json_get_int(int *store, json_t *val, const char *res) void json_get_int(int *store, json_t *val, const char *res)
{ {
json_t *entry = json_object_get(val, res); json_t *entry = json_object_get(val, res);
@ -898,6 +899,7 @@ static void json_get_int(int *store, json_t *val, const char *res)
return; return;
} }
*store = json_integer_value(entry); *store = json_integer_value(entry);
LOGDEBUG("Json found entry %s: %d", res, *store);
} }
static void json_get_bool(bool *store, json_t *val, const char *res) static void json_get_bool(bool *store, json_t *val, const char *res)
@ -913,6 +915,7 @@ static void json_get_bool(bool *store, json_t *val, const char *res)
return; return;
} }
*store = json_is_true(entry); *store = json_is_true(entry);
LOGDEBUG("Json found entry %s: %s", res, *store ? "true" : "false");
} }
static void parse_btcds(ckpool_t *ckp, json_t *arr_val, int arr_size) static void parse_btcds(ckpool_t *ckp, json_t *arr_val, int arr_size)

1
src/ckpool.h

@ -200,5 +200,6 @@ json_t *json_rpc_call(connsock_t *cs, const char *rpc_req);
int process_exit(ckpool_t *ckp, proc_instance_t *pi, int ret); int process_exit(ckpool_t *ckp, proc_instance_t *pi, int ret);
void json_get_string(char **store, json_t *val, const char *res); void json_get_string(char **store, json_t *val, const char *res);
void json_get_int(int *store, json_t *val, const char *res);
#endif /* CKPOOL_H */ #endif /* CKPOOL_H */

10
src/libckpool.h

@ -79,6 +79,16 @@
#define __maybe_unused __attribute__((unused)) #define __maybe_unused __attribute__((unused))
#define uninitialised_var(x) x = x #define uninitialised_var(x) x = x
#define MAX(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
#define MIN(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
typedef unsigned char uchar; typedef unsigned char uchar;
typedef struct timeval tv_t; typedef struct timeval tv_t;

22
src/stratifier.c

@ -245,7 +245,7 @@ struct worker_instance {
double dsps1440; double dsps1440;
tv_t last_share; tv_t last_share;
int64_t mindiff; /* User chosen mindiff */ int mindiff; /* User chosen mindiff */
}; };
/* Per client stratum instance == workers */ /* Per client stratum instance == workers */
@ -1588,6 +1588,7 @@ static int send_recv_auth(stratum_instance_t *client)
free(json_msg); free(json_msg);
if (likely(buf)) { if (likely(buf)) {
worker_instance_t *worker = client->worker_instance;
char *cmd = NULL, *secondaryuserid = NULL; char *cmd = NULL, *secondaryuserid = NULL;
char response[PAGESIZE] = {}; char response[PAGESIZE] = {};
json_error_t err_val; json_error_t err_val;
@ -1603,8 +1604,11 @@ static int send_recv_auth(stratum_instance_t *client)
val = json_loads(cmd, 0, &err_val); val = json_loads(cmd, 0, &err_val);
if (unlikely(!val)) if (unlikely(!val))
LOGWARNING("AUTH JSON decode failed(%d): %s", err_val.line, err_val.text); LOGWARNING("AUTH JSON decode failed(%d): %s", err_val.line, err_val.text);
else else {
json_get_string(&secondaryuserid, val, "secondaryuserid"); json_get_string(&secondaryuserid, val, "secondaryuserid");
json_get_int(&worker->mindiff, val, "difficultydefault");
client->suggest_diff = worker->mindiff;
}
if (!safecmp(response, "ok.auth") && secondaryuserid) { if (!safecmp(response, "ok.auth") && secondaryuserid) {
if (!user_instance->secondaryuserid) if (!user_instance->secondaryuserid)
user_instance->secondaryuserid = secondaryuserid; user_instance->secondaryuserid = secondaryuserid;
@ -2667,8 +2671,8 @@ static void sauth_process(ckpool_t *ckp, json_params_t *jp)
{ {
json_t *result_val, *json_msg, *err_val = NULL; json_t *result_val, *json_msg, *err_val = NULL;
stratum_instance_t *client; stratum_instance_t *client;
int mindiff, errnum = 0;
int64_t client_id; int64_t client_id;
int errnum = 0;
client_id = jp->client_id; client_id = jp->client_id;
@ -2698,6 +2702,18 @@ static void sauth_process(ckpool_t *ckp, json_params_t *jp)
json_object_set_new_nocheck(json_msg, "error", err_val ? err_val : json_null()); json_object_set_new_nocheck(json_msg, "error", err_val ? err_val : json_null());
json_object_set_nocheck(json_msg, "id", jp->id_val); json_object_set_nocheck(json_msg, "id", jp->id_val);
stratum_add_send(json_msg, client_id); stratum_add_send(json_msg, client_id);
if (!json_is_string(result_val) || !client->suggest_diff)
goto out;
/* Update the client now if they have set a valid mindiff different
* from the startdiff */
mindiff = MAX(ckp->mindiff, client->suggest_diff);
mindiff = MIN(ckp->startdiff, mindiff);
if (mindiff != client->diff) {
client->diff = mindiff;
stratum_send_diff(client);
}
out: out:
discard_json_params(&jp); discard_json_params(&jp);

Loading…
Cancel
Save